Skip to content

The official Go SDK for ShortLoop (shortloop.dev)

Notifications You must be signed in to change notification settings

short-loop/shortloop-go

Repository files navigation

Shortloop SDK for Go

shortloop-go provides client implementation of Shortloop SDK for the Go programming language.

Requirements

Current SDK version requires Go 1.17 or higher.
For Gin framework, it requires gin version 1.4.0 or higher.

Installation

shortloop-go can be installed like any other Go library through go get:

$ go get github.com/short-loop/shortloop-go@latest

Usage

  1. Import sdk in your code

    For gin:

    import "github.com/short-loop/shortloop-go/shortloopgin"

    For mux:

    import "github.com/short-loop/shortloop-go/shortloopmux"
  2. Initialize the sdk
    Example for gin:

    router := gin.Default()
    sdk, err := shortloopgin.Init(shortloopgin.Options{
        ShortloopEndpoint: "http://localhost:8080",
        ApplicationName:   "test-service-go",
        LoggingEnabled:    true,
        LogLevel:          "INFO",
    })
    if err != nil {
        fmt.Println("Error initializing shortloopgin: ", err)
    } else {
        router.Use(sdk.Filter())
    }

    Example for mux:

    mux := mux.NewRouter()
    sdk, err := shortloopmux.Init(shortloopmux.Options{
        ShortloopEndpoint: "http://localhost:8080",
        ApplicationName:   "test-service-go",
        LoggingEnabled:    true,
        LogLevel:          "INFO",
    })
    if err != nil {
        fmt.Println("Error initializing shortloopmux: ", err)
    } else {
        mux.Use(sdk.Filter)
    }