dusdk

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

Installation


go get github.com/DigitalUnion/dusdk

Quickstart


import (
	"github.com/DigitalUnion/dusdk"
	"github.com/goccy/go-json"
	"log"
)

func ExampleClient() {
	api := dusdk.NewClient("aaaaaa", "test", "aaaaaaaa")
	for i := 0; i < 10; i++ {
		r := api.Call("/geofence/v1/list_fence", nil)
		j, _ := json.Marshal(r)
		log.Println(string(j))
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a client representing a instance

func NewClient

func NewClient(clientId, secretKey, secretVal string) *Client

NewClient: create and return a new client

clientId identify of client secretKey key of secret secretVal value of secret

func (*Client) Call

func (p *Client) Call(method string, data []byte) (res Response)

Call: call remote function

Response response from remote server response if valid if error is nil

func (*Client) EnableTestMode

func (p *Client) EnableTestMode()

EnableTestMode: enable test mode

Warnning: if you call method with test mode ,the reponse will be different. So DO NOT use it on production mode

type Response

type Response struct {
	// Code response code
	//
	// |code  | describe                        |
	// |------|---------------------------------|
	// |0     | success                         |
	// |10000 | IP not in whitelist             |
	// |10001 | Request path error              |
	// |10002 | Internal server error           |
	// |10100 | Param cilent_id required        |
	// |10101 | Param client_id not found       |
	// |10102 | This service is not activated   |
	// |10200 | Secret key required             |
	// |10201 | Secret not found                |
	// |10202 | Decode failed                   |
	// |10203 | Get request body failed         |
	// |10300 | Service not found               |
	// |10999 | Other error                     |
	//
	// code 0 means success, others means errors
	Code string `json:"code,omitempty"`

	// Msg the message of response
	// if code not 0, the msg will tell you the reason
	Msg string `json:"msg,omitempty"`

	// Data the data of response, The responses are different depending on the service
	// if code not 0, the data will be nil
	Data interface{} `json:"data,omitempty"`
}

Response is the response of request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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