Go SDK

Overview

The generated Neurelo Go SDK provides easy access to your Neurelo APIs for Go applications.

Prerequisites

  • GO binaries are installed on your system and included in your path.

  • Download your generated SDK from the API pages of your project & move the generated SDK file neurelo-sdk-go-cmt_<id>.zip to your project root.

  • Tools for configuring environment variables (e.g. github.com/joho/godotenv) or simply export before starting your dev server (inline).

Installation

  • Copy the generated sdk neurelo-sdk-go-cmt_<>.zip to your project

  • Unzip the sdk to project_root/pkg/neurelo_sdk

  • Add the pkg directory to .gitignore file

  • Add neurelo_sdk to the go.mod file by running go mod edit -replace=github.com/<username>/neurelo-go-sdk=./pkg/neurelo_sdk

  • Your go.mod file should look like this:

module github.com/<username>/<project_name>

go 1.21.3

replace github.com/<username>/neurelo-go-sdk => ./pkg/neurelo_sdk

require (
	github.com/<username>/neurelo-go-sdk v0.0.1
)
  • You will also need to add the go workspace file by running this command - go work init && go work use ./pkg/neurelo_sdk . (Additionally, you can also add other packages to the go workspace file).

Usage

  • Make sure to set NEURELO_API_ENDPOINT and NEURELO_API_KEY env variables before using the client or you can set them in the client file.

  • Create a client file, so that it can be used by other files in the project.

package lib

import (
	"os"
    neurelo_sdk "github.com/smitpatelx/neurelo-go-htmx-example-sdk"
)

var NeureloClient *neurelo_sdk.APIClient

// Setup client after reading env variables or in main.go
func SetupClient() {
	sdk_config := neurelo_sdk.NewConfiguration()
	sdk_config.Host = os.Getenv("NEURELO_API_ENDPOINT")
	sdk_config.DefaultHeader["X-API-KEY"] = os.Getenv("NEURELO_API_KEY")
	sdk_config.Debug = false

	NeureloClient = neurelo_sdk.NewAPIClient(sdk_config)
}

API Usage

  • Use the client in other files to make API calls.

find_actor := lib.NeureloClient.ActorAPI.FindActor(context.Background()).Take(take).Skip(skip).Filter(filter);

res, _, err := find_actor.Execute()
if err != nil {
    fmt.Println(err)
    return nil
}

Last updated