Categorygithub.com/ding-live/ding-go
modulepackage
1.2.0
Repository: https://github.com/ding-live/ding-go.git
Documentation: pkg.go.dev

# README

Ding Go SDK

The Ding Go SDK allows Go backends to access the Ding API programmatically.

Requirements

Go 1.16 or higher

Installation

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

go mod init

Then, reference ding-go in a Go program with import:

import (
	ding "github.com/ding-live/ding-go"
)

Run any of the normal go commands (build/install/test). The Go toolchain will resolve and fetch the ding-go module automatically.

Alternatively, you can also explicitly go get the package into a project:

go get -u github.com/ding-live/ding-go

Documentation

Below are a few simple examples:

Create a new client

cfg := &ding.Config{
	CustomerUUID:      "f0b399ce-eead-4781-bab5-f63240e81a52",
	APIKey:            "87ydfsa987fdyas9h8f7y29ne87fyqds98af",
	MaxNetworkRetries: ding.Int(4),
}

c, err := ding.NewClient(cfg)

Send a message

This will send an OTP code to a client using the best route available

a, err := client.Authenticate(ding.AuthenticateOptions{
	PhoneNumber: "+33xxxxxxxxxx",
	IP:          ding.String("192.168.0.1"),
	DeviceType:  &ding.DeviceTypeIOS,
	AppVersion:  ding.String("1.2.0"),
	CallbackURL: ding.String("https://example.com/callback"),
})

Check a code

When the user enters the code into your app, check whether it is valid

a, err := client.Check("f0b399ce-eead-4781-bab5-f63240e81a52", "3588")

Retry an authentication

a, err := client.Retry("5071dbf5-78d0-497a-b844-c1231808c3e9")

Use a custom HTTP client

If you want more control on the HTTP requests that are performed by the client, you can use a custom HTTP client.

c, err := ding.NewClient(ding.Config{
	CustomerUUID:      "f0b399ce-eead-4781-bab5-f63240e81a52",
	APIKey:            "87ydfsa987fdyas9h8f7y29ne87fyqds98af",
	CustomHTTPClient:  &http.Client{Timeout: 10 * time.Second},
})

Configure logging

By default, the library logs error messages only (which are sent to stderr). Configure default logging using the LeveledLogger field:

config := &ding.Config{
    LeveledLogger: &ding.Logger{
        Level: ding.LevelInfo,
    },
}

It's possible to use non-Ding leveled loggers as well. Ding expects loggers to comply to the following interface:

type LeveledLogger interface {
	Debugf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
}

Some loggers like Logrus and Zap's SugaredLogger support this interface out-of-the-box so it's possible to set DefaultLeveledLogger to a *logrus.Logger or *zap.SugaredLogger directly. For others it may be necessary to write a thin shim layer to support them.

# Packages

No description provided by the author
No description provided by the author

# Functions

Int converts an int to a pointer to an int.
NewClient returns a new Ding client with a `Config` object.
String converts a string to a pointer to a string.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

DefaultLeveledLogger is the default logger that the library will use to log errors, warnings, and informational messages.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

AuthenticateOptions are the options used to authenticate a user.
Authentication is the result of an authentication request.
Check is the result of a check request.
Client is the main Ding client.
Config is the configuration required to instanciate a new client.
Logger is a leveled logger implementation.
Retry is the result of a retry request.

# Interfaces

LeveledLogger is an interface that can be implemented by any logger or a logger wrapper to provide leveled logging.

# Type aliases

DeviceType is the type of device used to authenticate.
No description provided by the author