Skip to content

uSpeedo/uspeedo-sdk-go

Repository files navigation

English | 简体中文

uspeedo Go SDK

GitHub release Go Report Card GoDoc GitHub

Installation

Requirements

  • Go 1.10+

Use go get

go get github.com/uspeedo/uspeedo-sdk-go

Note if meet network problem, you can use go proxy to speed up the downloaded, eg: use GOPROXY environment variable

export GOPROXY=https://goproxy.io

Replay the command to retry installation.

Use go mod

Add the following snippet to any code.

import _ "github.com/uspeedo/uspeedo-sdk-go"

And execute this commands:

go mod init
go mod tidy

Use dep

dep ensure -add github.com/uspeedo/uspeedo-sdk-go

First Using

Currently, Go SDK use PublicKey/PrivateKey as authentication method, the key can be found from:

Here is a simple example:

package main

import (
	"fmt"

	"github.com/uspeedo/uspeedo-sdk-go/uspeedo"
	"github.com/uspeedo/uspeedo-sdk-go/uspeedo/auth"
	"github.com/uspeedo/uspeedo-sdk-go/services/asms"
)

func main() {
	cfg := uspeedo.NewConfig()

	// replace the public/private key by your own
	credential := auth.NewCredential()
	credential.PrivateKey = "my_private_key"
	credential.PublicKey = "my_public_key"

	asmsClient := asms.NewClient(&cfg, &credential)

	req := asmsClient.NewSendBatchUSMSMessageRequest()
	req.ChargeType = uspeedo.String("Dynamic")
	req.TaskContent = []asms.SendBatchInfo{
		{
			TemplateId: "...",
			SenderId:   "",
			Target: []asms.SendBatchTarget{
				{
					Phone: "130xxxx1321",
				},
				{
					Phone: "130xxxx1321",
				},
			},
		},
	}

	// send request
	resp, err := asmsClient.SendBatchUSMSMessage(req)
	if err != nil {
		fmt.Printf("something bad happened: %s\n", err)
	} else {
		fmt.Printf("response of the request: %v\n", resp)
	}
}

Feedback & Contribution