Neurelo Build Docs
Neurelo Build Docs
  • Introduction
    • Core Concepts
    • Key Features
  • Getting Started
    • Sign-in/Sign-up
    • Dashboard
      • Collapsible Sidebar
      • Light/Dark Mode
      • Account Settings
      • Audit Events
      • User Management
        • Permissions (Member v/s Admin)
      • Org Settings
    • Starting your Neurelo Project
      • Quick Start Guide
      • Step 1 - Add a Data Source
      • Step 2 - Build Definitions
      • Step 3 - Create an Environment
      • Step 4 - Create an API Key
      • Step 5 - Start Runners
      • Try your Neurelo APIs
  • "How to" Videos
    • Product Overview
    • Neurelo APIs & SDKs
    • Project Setup
    • Definitions
    • Environments
    • Data Sources
    • Organization Management
    • Creating and Using Custom Queries
    • Using the Schema Builder to build Relationships
    • Mock Data Generation
  • Definitions
    • Neurelo Schema Editor
      • Schema Builder
      • JSON/YAML Editor
      • Schema Visualization: Entity-Relationship Diagram (ERD)
    • Custom APIs for Complex Queries
      • Write and Commit Custom Queries
      • AI-Assisted Query Generation
      • Deploying Custom API Endpoints
      • Using Variables in your Custom Query
    • Branches and Commits
    • API Docs
  • Environments
    • Creating a new Environment
    • API Playground
    • Observability
    • Migrations
    • API Keys
  • Data Sources
    • PostgreSQL
    • MySQL
    • MongoDB
  • Guides
    • Provisioning Cloud Databases for using with Neurelo
      • PostgreSQL
        • AWS RDS (PostgreSQL)
      • MySQL
        • AWS RDS (MySQL)
      • MongoDB Atlas
    • Mock Data Generation
    • Wipe Data Source
    • Remote Git Repository for Definitions
      • Connecting a Remote Git Repo
      • Creating Commits from Neurelo
      • Syncing Branches
    • Data Viewer
    • Environment/Data Source Tags
    • How to work with Embedded documents and References in MongoDB
    • How to download and use the Postman Collection for your Project
    • Building Python applications with Postgres and FastAPI
    • CI Integration using Neurelo CLI
    • Schema Migrations
    • Schema AI Assist
    • Auto-Introspection
    • Access Policies
    • User Auth
      • Google
      • GitHub
      • GitLab
    • MongoDB Atlas - Migrate GraphQL to Neurelo
    • MongoDB Atlas - Migrate REST Data APIs to Neurelo
  • MongoDB Atlas - Migrate REST Data APIs to Neurelo
  • MongoDB Atlas - Migrate GraphQL APIs to Neurelo
  • Neurelo Schema Language (NSL)
    • Example 1 - DVD Rentals
    • Example 2 - Simple "Posts" App
    • Example 3 - Bookstore
  • Neurelo API Reference (REST)
    • Examples of Neurelo Auto-Generated REST API endpoints
      • Example 1 - Simple “Posts” application
      • Example 2 - "DVD Rentals" application
      • Example 3 - "Bookstore” application
      • cURL API Examples
  • Neurelo API Reference (GraphQL)
  • SDKs
    • TypeScript / JavaScript SDK
    • Go SDK
    • Python SDK
      • Python SDK Tutorial -- News Application
        • News Application using Neurelo’s Python SDKs
  • CLI (Preview Version)
  • Self-Hosted Neurelo Gateways
  • Tutorials
    • Building a Real Time Chat Application with Neurelo and MongoDB using Python
    • Building A Financial Terminal with Neurelo and MongoDB in Rust
    • Building a Restaurant Management System with Neurelo and MongoDB using GraphQL in just a few minutes
    • Bringing Neurelo’s Data APIs to Life Instantly with MySQL
  • Project Examples
  • References
    • Supported Databases
    • Supported OS and Browsers
  • Support
Powered by GitBook
On this page
  • Overview
  • Prerequisites
  • Installation
  • Usage
  • API Usage
  • Setup Environment Variables (Optional)
  • Examples
  1. SDKs

Go SDK

Overview

Neurelo's Go SDK allows you to quickly and easily integrate your app with Neurelo APIs. This SDK is generated from the API spec and provides a set of methods to interact with the API endpoints. The generator creates a Go client that utilizes the std package net/http to make HTTP requests. Tested with Go v1.22.3

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-golang-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-golang-cmt_<>.zip to your project

  • Unzip the sdk to project_root/pkg/neurelo_sdk

  • Add the dependencies to your go.mod file

mkdir -p ./pkg/neurelo_sdk &&\
unzip neurelo-sdk-golang-cmt_<>.zip -d ./pkg/neurelo_sdk &&\
go get github.com/oapi-codegen/runtime

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.

// src/lib/client.go
package lib

import (
  "context"
  "net/http"
  "os"

  // Replace the <project_root> with your project url. eg: github.com/neurelo-public/neurelo-sdk
  neurelo_sdk "<project_root>/pkg/neurelo_sdk"
)

var ApiClient *neurelo_sdk.Client

func RequestEditor(ctx context.Context, req *http.Request) error {
  req.Header.Set("X-API-KEY", os.Getenv("NEURELO_API_KEY"))
  return nil
}

// Setup client after reading env variables or in main.go
func SetupApiClient() {
  hc := http.Client{}
  server := os.Getenv("NEURELO_API_ENDPOINT")
  api_client := neurelo_sdk.Client{
    Server: server,
    Client: &hc,
    RequestEditors: []neurelo_sdk.RequestEditorFn{
    RequestEditor,
    },
  }
  ApiClient = &api_client
}

API Usage

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

// main.go
package main

import (
  "context"
  "fmt"

  // Replace the <project_root> with your project url. eg: github.com/neurelo-public/neurelo-sdk
  neurelo_sdk "<project_root>/pkg/neurelo_sdk"
  lib "<project_root>/src/lib"
)

func Execute() {
  ctx := context.Background()

  take := 10
  skip := 0

  res, err := lib.ApiClient.FindActor(ctx, &neurelo_sdk.FindActorParams{
    Take: &take,
    Skip: &skip,
  })
  if err != nil {
    panic(err)
  }

  parsedRes, err := neurelo_sdk.ParseFindActorResponse(res)
  if err != nil {
    panic(err)
  }

  fmt.Println(string(parsedRes.Body))
}

func main() {
  lib.SetupApiClient()
  Execute()
}
  • Execute the main file to see the output

go run main.go

Setup Environment Variables (Optional)

  • Install the godotenv package

go get github.com/joho/godotenv
  • Create a .env file in the root of your project

touch .env &&\
echo "NEURELO_API_ENDPOINT=<api-endpoint>" >> .env &&\
echo "NEURELO_API_KEY=<api-key>" >> .env
  • Load the environment variables in the main.go file

// main.go
package main

import (
  // other imports ...
  godotenv "github.com/joho/godotenv"
)

func main() {
  godotenv.Load(".env")
  lib.SetupApiClient()
  Execute()
}

Examples

  • These examples are built to act as a starter template for your project

  • You can use these examples to understand how to use the SDK in your project

PreviousTypeScript / JavaScript SDKNextPython SDK

Last updated 9 months ago

To review an example of an application built using Neurelo's SDK, please visit:

Projects built using Neurelo SDKs