Go Library Quickstart
Configure Project
- First add the library module to your project.
go get github.com/dapi-co/dapi-go
- Create a Dapi app and products instances with your App Secret.
package main
import (
"github.com/dapi-co/dapi-go/app"
"github.com/dapi-co/dapi-go/auth"
"github.com/dapi-co/dapi-go/config"
"github.com/dapi-co/dapi-go/data"
"github.com/dapi-co/dapi-go/metadata"
"github.com/dapi-co/dapi-go/payment"
)
func main() {
// create a config object that holds the secret of this app
myAppConfig := &config.Config{
AppSecret: "YOUR_APP_SECRET",
}
// init a DapiApp instance
myApp := &app.DapiApp{
Config: myAppConfig,
}
// init the products you want to use
myAuth := auth.Auth{Config: myAppConfig}
myData := data.Data{Config: myAppConfig}
myPayment := payment.Payment{Config: myAppConfig}
myMetadata := metadata.Metadata{Config: myAppConfig}
// use any of the myApp, myAuth, myData, myPayment, or myMetadata methods..
}
- Now you can use any of the functions of the
DapiApp
instance,myApp
. Here is an example forGetAccounts
package main
import (
"github.com/dapi-co/dapi-go/app"
"github.com/dapi-co/dapi-go/config"
"github.com/dapi-co/dapi-go/data"
)
func main() {
// create a config object that holds the secret of this app
myAppConfig := &config.Config{
AppSecret: "YOUR_APP_SECRET",
}
// init the product you want to use
myData := data.Data{Config: myAppConfig}
// use any of the `myData` methods..
// provide the operationID and the userInputs only if needed
accountsResp, err := myData.GetAccounts("YOUR_ACCESS_TOKEN", "YOUR_USER_SECRET", nil, "")
if err != nil {
// handle the error..
return
}
if accountsResp.Status != constants.StatusDone {
// handle the unsuccessful response..
return
}
accounts := accountsResp.Accounts
// use the got accounts array..
}
Updated about 1 year ago