Magic for Go

Magic for Go

Reference for the Magic Admin SDK for Golang: https://github.com/magiclabs/magic-admin-go

#Overview

The Magic SDK for server-side Golang makes it easy to leverage Decentralized ID Tokens to authenticate your users for your app. This guide will cover some important topics for getting started with server-side APIs and to make the most of Magic's features.

  • Install the Magic Admin SDK to get started
  • View the API documentation below to learn the methods you'll be using
  • Go to Examples for an introduction to common patterns and use-cases
note

Looking for a client-side API instead? Check out:

👉 Magic Client SDK for web

👉 Magic Client SDK for React Native

#Installation

The SDK requires Golang 1.13+ and Go Modules. To make sure your project is using Go Modules, you can look for go.mod file in your project's root directory. If it exits, then you are already using the Go Modules. If not, you can follow this guide to migrate to Go Modules.

Simply reference magic-admin-go in a Go program with an import of the SDK:

Go
01import (
02    ...
03    "github.com/magiclabs/magic-admin-go"
04    ...
05)

Run any of the normal go commands (ex: build/install). The Go toolchain will take care of fetching the SDK automatically.

Alternatively, you can explicitly go get the package into a project:

Bash
01go get github.com/magiclabs/magic-admin-go

#Creating an SDK Client Instance

The Client handles all the Magic API requests for your application. To instantiate:

Go
01package main
02
03import (
04    "github.com/magiclabs/magic-admin-go"
05    "github.com/magiclabs/magic-admin-go/client"
06)
07
08func main() {
09    m := client.New("<YOUR_API_SECRET_KEY>", magic.NewDefaultClient())
10    userInfo, err := m.User.GetMetadataByToken("<DID_TOKEN>")
11    ...
12}

#Creating a Token Instance

The Token provides methods to interact with DID Token.

Go
01package main
02
03import (
04    "github.com/magiclabs/magic-admin-go"
05    "github.com/magiclabs/magic-admin-go/token"
06)
07
08func main() {
09    tk, err := token.NewToken(did)
10    if err != nil {
11        return
12    }
13
14    if err := tk.Validate(); err != nil {
15        return
16    }
17    ...
18}

Did you find what you were looking for?

Did you find what you were looking for?