Go Library Quickstart

Configure Project

  1. First add the library module to your project.
go get github.com/dapi-co/dapi-go
  1. 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..
}
  1. Now you can use any of the functions of the DapiApp instance, myApp. Here is an example for GetAccounts
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..
}