Files
m3o-go/id/id.go
2021-10-28 13:52:36 +00:00

49 lines
1.0 KiB
Go
Executable File

package id
import (
"github.com/m3o/m3o-go/client"
)
func NewIdService(token string) *IdService {
return &IdService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type IdService struct {
client *client.Client
}
// Generate a unique ID. Defaults to uuid.
func (t *IdService) Generate(request *GenerateRequest) (*GenerateResponse, error) {
rsp := &GenerateResponse{}
return rsp, t.client.Call("id", "Generate", request, rsp)
}
// List the types of IDs available. No query params needed.
func (t *IdService) Types(request *TypesRequest) (*TypesResponse, error) {
rsp := &TypesResponse{}
return rsp, t.client.Call("id", "Types", request, rsp)
}
type GenerateRequest struct {
// type of id e.g uuid, shortid, snowflake (64 bit), bigflake (128 bit)
Type string `json:"type"`
}
type GenerateResponse struct {
// the unique id generated
Id string `json:"id"`
// the type of id generated
Type string `json:"type"`
}
type TypesRequest struct {
}
type TypesResponse struct {
Types []string `json:"types"`
}