Lybic Docs

Get Started with Go

Learn how to install and configure the Lybic Go SDK.

This guide will walk you through the process of installing and setting up the Lybic SDK for your Go applications.

Installation

First, add the Lybic Go SDK to your project as a dependency.

go get github.com/lybic/lybic-sdk-go

Initialization & Configuration

Initialize the client in your Go application. You can pass nil to the NewClient function to configure the client from environment variables, or provide a lybic.Config struct for programmatic configuration.

Basic Initialization

This example initializes the client using environment variables.

package main

import (
	"context"
	"fmt"

	"github.com/lybic/lybic-sdk-go"
)

func main() {
	// Passing nil initializes a client with environment variables
	client, err := lybic.NewClient(nil)
	if err != nil {
		panic(err)
	}

	ctx := context.Background()
	sandboxes, err := client.ListSandboxes(ctx)
	if err != nil {
		fmt.Printf("Error listing sandboxes: %v", err)
		return
	}
	fmt.Printf("sandboxes: %+v", sandboxes)
}

Programmatic Configuration

You can also configure the client programmatically by creating a Config object.

config := lybic.NewConfig() // Initializes with defaults and env variables
config.OrgId = "your-org-id"
config.ApiKey = "your-api-key"
config.Timeout = 20 // seconds

client, err := lybic.NewClient(config)
if err != nil {
    panic(err)
}

Configuration Options

The client can be configured with the following options, either through the Config struct or environment variables:

Struct FieldEnvironment VariableDescriptionDefault Value
OrgIdLYBIC_ORG_IDRequired. Your organization ID.""
ApiKeyLYBIC_API_KEYYour API key for authentication.""
EndpointLYBIC_API_ENDPOINTThe API endpoint URL.https://api.lybic.cn
Timeout-HTTP request timeout in seconds.10
ExtraHeaders-A map of extra HTTP headers to send with each request.nil
Logger-A custom logger instance.nil (disabled)