TrademarkTrademark
Ctrl k
Search docs...
Sdk

Golang

Last update: August 25, 2025
Thumbnail of Golang
Choose your language and install the appropriate SDK:
Bash
go get github.com/melvinodsa/go-iam-sdk/golang
Go
package main

import (
    "context"
    "log"
    goiam "github.com/melvinodsa/go-iam-sdk/golang"
)

func main() {
    service := goiam.NewService(
        "https://your-go-iam-server.com",
        "your-client-id",
        "your-client-secret"
    )

    // Ready to use!
}
Verify Authentication Code:
Go
ctx := context.Background()
token, err := service.Verify(ctx, "auth-code") 
if err != nil {
  log.Fatalf("Failed to verify: %v", err)
}
fmt.Println("Access Token:", token)
Once authenticated, retrieve current user details:
Go
user, err := service.Me(ctx, token)
if err != nil {
  log.Fatalf("Failed to fetch user: %v", err)
}
fmt.Printf("User: %+v\n", user)
Create and manage resources in your application:
Go
resource := &golang.Resource{
    ID:          "resource-id",
    Name:        "User Dashboard",
    Description: "Main user dashboard resource",
    Tags:        []string{"dashboard", "user"},
}

err = service.CreateResource(ctx, resource)
if err != nil {
    log.Fatalf("Failed to create resource: %v", err)
}
For production applications, use environment variables:
Bash
# .env file
GO_IAM_BASE_URL=https://your-go-iam-server.com
GO_IAM_CLIENT_ID=your-client-id
GO_IAM_CLIENT_SECRET=your-client-secret
Go
import "os"

service := goiam.NewService(
    os.Getenv("GO_IAM_BASE_URL"),
    os.Getenv("GO_IAM_CLIENT_ID"),
    os.Getenv("GO_IAM_CLIENT_SECRET"),
)
Go
type User struct {
	Id         string                  `json:"id"`
	ProjectId  string                  `json:"project_id"`
	Name       string                  `json:"name"`
	Email      string                  `json:"email"`
	Phone      string                  `json:"phone"`
	Enabled    bool                    `json:"enabled"`
	ProfilePic string                  `json:"profile_pic"`
	Expiry     *time.Time              `json:"expiry"`
	Roles      map[string]UserRole     `json:"roles"`
	Resources  map[string]UserResource `json:"resources"`
	Policies   map[string]UserPolicy   `json:"policies"`
	CreatedAt  *time.Time              `json:"created_at"`
	CreatedBy  string                  `json:"created_by"`
	UpdatedAt  *time.Time              `json:"updated_at"`
	UpdatedBy  string                  `json:"updated_by"`
}

type UserPolicy struct {
	Name    string            `json:"name"`
	Mapping UserPolicyMapping `json:"mapping,omitempty"`
}

type UserPolicyMapping struct {
	Arguments map[string]UserPolicyMappingValue `json:"arguments,omitempty"`
}

type UserPolicyMappingValue struct {
	Static string `json:"static,omitempty"`
}

type UserRole struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

type UserResource struct {
	RoleIds   map[string]bool `bson:"role_ids"`
	PolicyIds map[string]bool `bson:"policy_ids"`
	Key       string          `json:"key"`
	Name      string          `json:"name"`
}
On this page
© 2025 Go IAM. Open source under Apache 2.0 License.