platform

package module
v0.0.0-...-7e6df26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

README

English | 简体中文

platform-sdk-go

Introduction

Golang version SDK for accessing the fundamental services on the Ao.Space platform.

Installation

  1. Install using go get

    go get github.com/ao-space/platform-sdk-go/v2
    
  2. Import into your code

    import "github.com/ao-space/platform-sdk-go/v2"
    

Quick Start

Each interface has a corresponding Request structure and a Response structure. For example, the ObtainBoxRegKey interface has corresponding request and response structures named ObtainBoxRegKeyRequest and ObtainBoxRegKeyResponse, respectively.

Below is an example of how to use the SDK for obtaining an access token.

package main

import (
	"fmt"
	"github.com/ao-space/platform-sdk-go/utils"
	"github.com/ao-space/platform-sdk-go/v2"
)

func main() {
    
	// Create a client: specify the Host of the platform's fundamental
    // service and optionally set the transport manually
	client := platform.NewClientWithHost(platform.AoSpaceDomain, nil)
    
	// Optionally set the request ID for the most recent request
	client.SetRequestId("XXXXX")
    
	// Request parameters
	input := &platform.ObtainBoxRegKeyRequest{
		BoxUUID:    "XXXXX",
		ServiceIds: []string{"XXXXX"},
	}
	response, err := client.ObtainBoxRegKey(input)

	if err != nil {
		panic(err)
	}
	fmt.Println(utils.ToString(response))
}

Documentation

SDK Functionality Examples
  1. Obtain Box_Reg_Key

    • Used to authenticate the identity of the device on the space platform and generate box_reg_keys.
    client = platform.NewClientWithHost("XXXXXX", nil)
    
    resp, err := client.ObtainBoxRegKey(&platform.ObtainBoxRegKeyRequest{
    	BoxUUID:    "XXXXX",
    	ServiceIds: []string{"XXXXX"},
    })
    if err != nil {
    	fmt.Println(err)
    	return
    }
    fmt.Println(resp)
    
  2. Register Device

    • Register AO.space device, and the space platform assigns network client information to it
    resp, err := client.RegisterDevice()
    if err != nil {
    	fmt.Println(err)
    	return
    }
    fmt.Println(resp)
    
  3. Delete Device

    • Delete the registration information of AO.space device, including user registration information, client registration information, network resources, etc
    err := client.DeleteDevice()
    if err != nil {
    	fmt.Println(err)
    	return
    }
    
  4. Register User

    • Register users and synchronize their binding clients
    resp, err := client.RegisterUser(&platform.RegisterUserRequest{
    	UserID:     "XXX", // User ID
    	Subdomain:  "XXX", //The subdomain name specified by the user
        UserType:   "XXX", //User type (administrator, member), value: user_admin、user_member
    	ClientUUID: "XXX", //The UUID of the client
    })
    if err != nil {
    	fmt.Println(err)
    	return
    }
    fmt.Println(resp)
    
  5. Generate User Domain Name

    • Generate the user's subdomain name, and the subdomain name is unique globally
    resp, err := client.GenerateUserDomain(&platform.GenerateUserDomainRequest{
    	EffectiveTime: "XXX", //Validity period, in seconds, up to 7 days
    })
    if err != nil {
    	fmt.Println(err)
    	return
    }
    fmt.Println(resp)
    
  6. Modify User Domain Name

    • Modify the user's subdomain name, still retaining the user's historical subdomain name
    resp, err := client.ModifyUserDomain(&platform.ModifyUserDomainRequest{
    	UserId:    "XXX",
    	Subdomain: "XXX",
    })
    if err != nil {
    	fmt.Println(err)
    	return
    }
    fmt.Println(resp)
    
  7. Delete User

    • Delete user registration information, including client registration information, etc
    err := client.DeleteUser("your userId")
    if err != nil {
    	fmt.Println(err)
    	return
    }
    
  8. Register Client

    • Register Client
    resp, err := client.RegisterClient(&platform.RegisterClientRequest{
    	UserId:     "XXX",
    	ClientUUID: "XXX",
    	ClientType: "XXX", //客户端类型(绑定、扫码授权),取值:client_bind、client_auth
    })
    if err != nil {
    	fmt.Println(err)
    	return
    }
    fmt.Println(resp)
    
  9. Delete Client

    • Delete client registration information
    err := client.DeleteClient(&platform.DeleteClientRequest{
    	UserId:     "XXX",
    	ClientUUID: "XXX",
    })
    if err != nil {
    	fmt.Println(err)
    	return
    }
    
  10. Space Platform Migration

    • Used to migrate AO.space device data to the new space platform
    resp, err := client.SpacePlatformMigration(&platform.SpacePlatformMigrationRequest{
    	NetworkClientId: "XXX",
    	UserInfos: []platform.UserMigrationInfo{
    		platform.UserMigrationInfo{
    			UserId:     "XXX",
    			UserDomain: "XXX",
    			UserType:   "XXX",
    			ClientInfos: []platform.ClientInfo{
    				platform.ClientInfo{
    					ClientUUID: "XXX",
    					ClientType: "XXX",
    				},
    			},
    		},
    	},
    })
    if err != nil {
    	fmt.Println(err)
    	return
    }
    
  11. Space Platform Migration Out

    • Used for domain name redirection on old space platforms
    resp, err := client.SpacePlatformMigrationOut(&platform.SpacePlatformMigrationOutRequest{
    	UserDomainRouteInfos: []platform.UserDomainRouteInfo{
    		platform.UserDomainRouteInfo{
    			UserId:             "XXX",
    			UserDomainRedirect: "XXX", //Redirected user domain name
    		},
    	}})
    
API Reference

Documentation

Index

Constants

View Source
const (
	JSON      = "application/json"
	UserAgent = "go-sdk-v2"
	NULL      = ""
	HTTPS     = "https"
)
View Source
const (
	ApiVersion    = 2
	AoSpaceDomain = "ao.space"
)

Variables

This section is empty.

Functions

func NewDefaultTransport

func NewDefaultTransport() *http.Transport

Types

type Api

type Api struct {
	Method             string `json:"method"`
	Uri                string `json:"uri"`
	BriefUri           string `json:"briefUri"`
	CompatibleVersions []int  `json:"compatibleVersions"`
	Type               string `json:"type"`
	Desc               string `json:"desc"`
}

type Client

type Client struct {
	HttpClient   *http.Client
	BoxUUID      string
	RequestId    string
	TokenResults *TokenResults
	BaseURL      *url.URL
	Logger       *zap.SugaredLogger
	Ability      map[string]map[string]map[int]int
	// contains filtered or unexported fields
}

func NewClientWithHost

func NewClientWithHost(Host string, transport *http.Transport) (*Client, error)

NewClientWithHost Host 是服务所在主机 transport 是连接池相关的配置

func (*Client) DeleteClient

func (c *Client) DeleteClient(input *DeleteClientRequest) error

func (*Client) DeleteDevice

func (c *Client) DeleteDevice() error

DeleteDevice 删除设备

func (*Client) DeleteUser

func (c *Client) DeleteUser(userID string) error

DeleteUser 删除用户

func (*Client) FlushAbilityWithDuration

func (c *Client) FlushAbilityWithDuration(duration time.Duration) func()

func (*Client) GenerateUserDomain

func (c *Client) GenerateUserDomain(input *GenerateUserDomainRequest) (*GenerateUserDomainResponse, error)

func (*Client) GetAbility

func (c *Client) GetAbility() (*GetAbilityResponse, error)

func (*Client) GetStatus

func (c *Client) GetStatus() (*GetStatusResponse, error)

func (*Client) IsAvailable

func (c *Client) IsAvailable(uri string, method string) bool

func (*Client) ModifyUserDomain

func (c *Client) ModifyUserDomain(input *ModifyUserDomainRequest) (*ModifyUserDomainResponse, error)

func (*Client) ObtainBoxRegKey

func (c *Client) ObtainBoxRegKey(input *ObtainBoxRegKeyRequest) (*ObtainBoxRegKeyResponse, error)

GetBoxRegKey 获取访问令牌

func (*Client) RegisterClient

func (c *Client) RegisterClient(input *RegisterClientRequest) (*RegisterClientResponse, error)

func (*Client) RegisterDevice

func (c *Client) RegisterDevice() (*RegisterDeviceResponse, error)

RegisterDevice 注册设备

func (*Client) RegisterUser

func (c *Client) RegisterUser(input *RegisterUserRequest) (*RegisterUserResponse, error)

func (*Client) Send

func (c *Client) Send(op *Operation, input []byte) (*http.Response, error)

func (*Client) SetBaseUrl

func (c *Client) SetBaseUrl(Host string)

func (*Client) SetRequestId

func (c *Client) SetRequestId(requestId string) *Client

func (*Client) SetTransport

func (c *Client) SetTransport(transport *http.Transport)

func (*Client) SetZapLogger

func (c *Client) SetZapLogger(logger *zap.SugaredLogger)

func (*Client) SpacePlatformMigration

func (c *Client) SpacePlatformMigration(input *SpacePlatformMigrationRequest) (*SpacePlatformMigrationResponse, error)

func (*Client) SpacePlatformMigrationOut

func (c *Client) SpacePlatformMigrationOut(input *SpacePlatformMigrationOutRequest) (*SpacePlatformMigrationOutResponse, error)

type ClientInfo

type ClientInfo struct {
	ClientUUID string `json:"clientUUID"`
	ClientType string `json:"clientType"`
}

type DeleteClientRequest

type DeleteClientRequest struct {
	UserId     string
	ClientUUID string
}

type GenerateUserDomainRequest

type GenerateUserDomainRequest struct {
	EffectiveTime int `json:"effectiveTime"`
}

type GenerateUserDomainResponse

type GenerateUserDomainResponse struct {
	BoxUUID   string `json:"boxUUID"`
	Subdomain string `json:"subdomain"`
	ExpiresAt string `json:"expiresAt"`
}

type GetAbilityResponse

type GetAbilityResponse struct {
	PlatformApis []Api `json:"platformApis"`
}

type GetStatusResponse

type GetStatusResponse struct {
	Status  string `json:"status"`
	Version string `json:"version"`
}

type ModifyUserDomainRequest

type ModifyUserDomainRequest struct {
	UserId    string `json:"-"`
	Subdomain string `json:"subdomain"`
}

type ModifyUserDomainResponse

type ModifyUserDomainResponse struct {
	Success    bool     `json:"success"`
	BoxUUID    string   `json:"boxUUID,omitempty"`
	UserId     string   `json:"userId,omitempty"`
	Subdomain  string   `json:"subdomain,omitempty"`
	Code       int      `json:"code,omitempty"`
	Error      string   `json:"error,omitempty"`
	Recommends []string `json:"recommends,omitempty"`
}

type ObtainBoxRegKeyRequest

type ObtainBoxRegKeyRequest struct {
	BoxUUID    string   `json:"boxUUID"`
	ServiceIds []string `json:"serviceIds"`
	Sign       string   `json:"sign,optional"`
}

type ObtainBoxRegKeyResponse

type ObtainBoxRegKeyResponse struct {
	BoxUUID      string         `json:"boxUUID"`
	TokenResults []TokenResults `json:"tokenResults"`
}

type Operation

type Operation struct {
	Method string
	Url    string
}

func (*Operation) SetOperation

func (op *Operation) SetOperation(method string, URL *url.URL)

type RegisterClientRequest

type RegisterClientRequest struct {
	UserId     string `json:"-"`
	ClientUUID string `json:"clientUUID"`
	ClientType string `json:"clientType"`
}

type RegisterClientResponse

type RegisterClientResponse struct {
	BoxUUID    string `json:"boxUUID"`
	UserId     string `json:"userId"`
	ClientUUID string `json:"clientUUID"`
	ClientType string `json:"clientType"`
}

type RegisterDeviceResponse

type RegisterDeviceResponse struct {
	BoxUUID       string        `json:"boxUUID"`
	NetWorkClient netWorkClient `json:"networkClient"`
}

type RegisterUserRequest

type RegisterUserRequest struct {
	UserID     string `json:"userId"`
	Subdomain  string `json:"subdomain"`
	UserType   string `json:"userType"`
	ClientUUID string `json:"clientUUID"`
}

type RegisterUserResponse

type RegisterUserResponse struct {
	BoxUUID    string `json:"boxUUID"`
	UserID     string `json:"userId"`
	UserDomain string `json:"userDomain"`
	UserType   string `json:"userType"`
	ClientUUID string `json:"clientUUID"`
}

type SpacePlatformMigrationOutRequest

type SpacePlatformMigrationOutRequest struct {
	UserDomainRouteInfos []UserDomainRouteInfo `json:"userDomainRouteInfos"`
}

type SpacePlatformMigrationOutResponse

type SpacePlatformMigrationOutResponse struct {
	BoxUUID              string                `json:"boxUUID"`
	UserDomainRouteInfos []UserDomainRouteInfo `json:"userDomainRouteInfos"`
}

type SpacePlatformMigrationRequest

type SpacePlatformMigrationRequest struct {
	NetworkClientId string              `json:"networkClientId"`
	UserInfos       []UserMigrationInfo `json:"userInfos"`
}

type SpacePlatformMigrationResponse

type SpacePlatformMigrationResponse struct {
	BoxUUID       string              `json:"boxUUID"`
	NetworkClient netWorkClient       `json:"netWorkClient"`
	UserInfos     []UserMigrationInfo `json:"userInfos"`
}

type TokenResults

type TokenResults struct {
	ServiceId string    `json:"serviceId"`
	BoxRegKey string    `json:"boxRegKey"`
	ExpiresAt time.Time `json:"expiresAt"`
}

type UserDomainRouteInfo

type UserDomainRouteInfo struct {
	UserId             string `json:"userId"`
	UserDomainRedirect string `json:"userDomainRedirect"`
}

type UserMigrationInfo

type UserMigrationInfo struct {
	UserId      string       `json:"userId"`
	UserDomain  string       `json:"userDomain"`
	UserType    string       `json:"userType"`
	ClientInfos []ClientInfo `json:"clientInfos"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL