Go Quickstart

Getting started with the Go Sift client library

Credentials

Before starting this section be sure to retrieve your API key and the appropriate Sift URL for your provisioned environment. Instructions on how to retrieve the API key and URL and can be found in the authentication section of the documentation.

To connect to Sift's gRPC API using Go we will use github.com/sift-stack/sift/go.

  1. Begin by creating a new Go module with go mod init and install the Sift Go package:

    go get github.com/sift-stack/sift/go
  2. With our dependency installed, copy-paste the following into your main.rs:

    package main
     
    import (
    	"context"
    	"fmt"
    	"log"
    	"os"
     
    	"github.com/sift-stack/sift/go/gen/sift/ping/v1"
    	"github.com/sift-stack/sift/go/grpc"
    )
     
    func main() {
    	ctx := context.Background()
    	channelConfig := grpc.SiftChannelConfig{
    		Uri:    os.Getenv("SIFT_URI"),
    		Apikey: os.Getenv("SIFT_API_KEY"),
    	}
    	conn, err := grpc.UseSiftChannel(ctx, channelConfig)
    	if err != nil {
    		log.Fatalln(err)
    	}
    	pingClient := pingv1.NewPingServiceClient(conn)
    	res, err := pingClient.Ping(ctx, &pingv1.PingRequest{})
    	if err != nil {
    		log.Fatalln(err)
    	}
    	fmt.Println(res.Response)
    }
  3. Execute the program from your commandline with the SIFT_URI and SIFT_API_KEY environment variables from the authentication page:

    BASE_URI=$SIFT_GRPC_URL:$PORT_NUM SIFT_API_KEY=$API_KEY go run .

    Note about the URL

    Do note that the Go gRPC package expects the URL to exclude the scheme (i.e. https://) but include the port number which is 433.

    If everything was setup correctly you should see the following printed to your standard output:

    Hello from Sift!

On this page

No Headings