Changelog

Go Backend Server

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,
	}
}

Configure SDK Server

  1. Follow the steps in Configure Project first in order to obtain and import the library.

  2. You can use the DapiApp instance to handle requests to a specific endpoint in your server. Our code will basically update the request to add your app's appSecret to it, and forward the request to Dapi, then respond back with the got response.

package main

import (
	"log"
	"net/http"

	"github.com/dapi-co/dapi-go/app"
	"github.com/dapi-co/dapi-go/config"
)

func main() {
	// create a config object that holds the secret of this app
	myAppConfig := &config.Config{
		AppSecret: "YOUR_APP_SECRET",
	}

	// init the a DapiApp instance
	myApp := &app.DapiApp{
		Config: myAppConfig,
	}

	// start a simple server that listens on the provided endpoint, and handles requests
	// through the handler of the DapiApp instance.
	err := http.ListenAndServe("YOUR_ADDRESS", http.HandlerFunc(myApp.HandleSDKDapiRequests))
	if err != nil {
		log.Fatal(err)
	}
}