mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-21 06:25:08 +00:00
Commit from m3o/m3o action
This commit is contained in:
48
go/id/id.go
Executable file
48
go/id/id.go
Executable file
@@ -0,0 +1,48 @@
|
||||
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"`
|
||||
}
|
||||
Reference in New Issue
Block a user