/go-sdk

Nitric Multi-cloud Client Golang SDK

Primary LanguageGoApache License 2.0Apache-2.0

Nitric Logo

Go Report Card test status codecov

Nitric SDK for Go

Client libarary for interfacing with the Nitric APIs as well as the creation of golang functions with Nitric.

Quick Start

Using the Nitric CLI

  1. Get the Nitric CLI
  2. Create a new Nitric Project nitric make:project <my-new-project>
  3. Select function/golang15 as a starter function

Using the Nitric SDK

Creating a new API clients

import "github.com/nitrictech/go-sdk/api/events"

// NitricFunction - Handles individual function requests (http, events, etc.)
func createNitricClient() {
	ec, err := events.New()

  if err != nil {
    // Do something with err
  }

	// use the new events client
	// ec.Topic("my-topic").Publish(...)
}

Starting a Nitric FaaS server

package main

import "github.com/nitrictech/go-sdk/faas"

// NitricFunction - Handles individual function requests (http, events, etc.)
func NitricFunction(trigger *faas.NitricTrigger) (*faas.TriggerResponse, error) {
	// Construct a default response base on the existing trigger context
	resp := trigger.DefaultResponse()
	resp.SetData([]byte("Hello Nitric"))

	return resp, nil
}

func main() {
	faas.Start(NitricFunction)
}