GithubHelp home page GithubHelp logo

go-datera's Introduction

Datera Golang SDK

Building

Requires Go 1.8+ You can download the latest version of Go here

$ make

Running Tests

$ make test

Getting Started

import (
    "fmt"
    udc "github.com/Datera/go-udc/pkg/udc"
    dsdk "github.com/Datera/go-sdk/pkg/dsdk"
)

func main() {

    // Get Universal Datera Config (UDC).  See http://github.com/Datera/go-udc
    c, err = udc.GetConfig()
    if err != nil {
        panic(err)
    }

    // Instantiate SDK with UDC
    sdk, err := dsdk.NewSdk(udc, true)
    if err != nil {
        panic(err)
    }

    // Run HealthCheck
    if err = sdk.HealthCheck(); err != nil {
        panic(err)
    }

    // Get Context for future requests
    ctxt := sdk.NewContext()

    // You can also use your own context by providing one with
    // a "tid" key
    ctxt := context.Background()
    ctxt = context.WithValue(ctxt, "tid", "C8DF241A-FF24-4939-B8CE-987B2344FF23")
    ctxt = sdk.WithContext(ctxt)

    // NOTE: You MUST provide a valid ctxt object with each request to the
    // SDK.  Not doing so will result in a panic.  A valid ctxt object
    // contains the following keys:
    // "tid" -- A uuid or other string indicating the current transaction
    //          for tracing purposes
    // "conn" -- An ApiConnection object reference.  This is obtained via
    //           the sdk.WithContext(ctxt) function

    // List AppInstances
    params := dsdk.ListParams{
        Limit:  maxEntries,
        Offset: startToken,
    }
    ais, apierr, err := r.sdk.AppInstances.List(&dsdk.AppInstancesListRequest{
        Ctxt:   ctxt,     // This is required, see note above
        Params: params,   // These can be omitted if uneeded
    })
    if err != nil {
        panic(err)
        return nil, err
    } else if apierr != nil {
        panic(fmt.Errorf("%#v", apierr))
    }
    for _, ai := range ais {
        fmt.Println(ai.Name)
    }

    // Get System Attributes
    sys, apierr, err := sdk.System.Get(&dsdk.SystemGetRequest{Ctxt: ctxt})
    if err != nil {
        panic(err)
        return nil, err
    } else if apierr != nil {
        panic(fmt.Errorf("%#v", apierr))
    }
    fmt.Printf("System: %s\n", dsdk.Pretty(sys))
}

All requests made by the Datera Golang SDK are within the same tenant specified at instantiation time. If multiple tenants are desired, multiple SDK objects must be used, each with a different tenant. You can accomplish this with the following code

import (
    udc "github.com/Datera/go-udc/pkg/udc"
)

c1 := &udc.UDC{
    Username: "my-user"
    Password: "my-pass"
    MgmtIp: "1.1.1.1"
    ApiVersion: "2.2"
    Tenant: "tenant-A"
}
c2 := &udc.UDC{
    Username: "my-user"
    Password: "my-pass"
    MgmtIp: "1.1.1.1"
    ApiVersion: "2.2"
    Tenant: "tenant-B"
}

sdkA, err := dsdk.NewSdk(c1, true)
if err != nil {
    panic(err)
}

sdkB, err := dsdk.NewSdk(c2, true)
if err != nil {
    panic(err)
}

Now all requests made with sdkA will go to "tenant-A", all requests with sdkB will be routed to "tenant-B". Changing the tenant for an existing SDK object is currently unsupported.

Please consult the test files for more in depth API usage

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.