go
square
go install github.com/KoeInoue/square-go-sdk
or
import the package in a file where you want to use the package
import "github.com/KoeInoue/square-go-sdk"
then run
go mod tidy
export SQUARE_ACCESS_TOKEN=yourSandboxAccessToken
export ENV=dev
※ ENV is a variable that just identifies the environment
package main
import (
"os"
"github.com/KoeInoue/square-go-sdk"
"github.com/KoeInoue/square-go-sdk/http"
"github.com/KoeInoue/square-go-sdk/models"
)
func main() {
client := getClient()
client.CustomerApi.CreateCustomer()
}
func getClient() *http.Client {
envType := os.Getenv("ENV")
accessToken := os.Getenv("SQUARE_ACCESS_TOKEN")
if envType != "production" {
return http.NewClient(square.Config[square.Sandbox]{
AccessToken: accessToken,
Environment: square.Environments.Sandbox,
})
} else {
return http.NewClient(square.Config[square.Production]{
AccessToken: accessToken,
Environment: square.Environments.Production,
})
}
}