Skip to content

Praveengostu/schematics-go-sdk

 
 

Repository files navigation

Build Status

IBM Cloud Schematics Go SDK 0.0.2

Go client library to interact with the various IBM Cloud Schematics APIs.

Disclaimer: this SDK is being released initially as a pre-release version. Changes might occur which impact applications that use this SDK.

Table of Contents

Overview

The IBM Cloud Schematics Go SDK allows developers to programmatically interact with the following IBM Cloud services:

Service Name Package name
Schematics schematicsv1

Prerequisites

  • An IBM Cloud account.
  • An IAM API key to allow the SDK to access your account. Create one here.
  • Go version 1.12 or above.

Installation

The current version of this SDK: 0.0.2

There are a few different ways to download and install the Schematics Go SDK project for use by your Go application:

go get command

Use this command to download and install the SDK to allow your Go application to use it:

go get -u github.com/IBM/schematics-go-sdk

Go modules

If your application is using Go modules, you can add a suitable import to your Go application, like this:

import (
	"github.com/IBM/schematics-go-sdk/schematicsv1"
)

then run go mod tidy to download and install the new dependency and update your Go application's go.mod file.

dep dependency manager

If your application is using the dep dependency management tool, you can add a dependency to your Gopkg.toml file. Here is an example:

[[constraint]]
  name = "github.com/IBM/schematics-go-sdk"
  version = "0.0.2"

then run dep ensure.

Authentication

The library requires Identity and Access Management (IAM) to authenticate requests. There are several ways to set the properties for authentication

  1. As environment variables
  2. The programmatic approach
  3. With an external credentials file

Authenticate with environment variables

For Schematics IAM authentication set the following environmental variables by replacing with your proper service credentials.

SCHEMATICS_URL = https://schematics.cloud.ibm.com
SCHEMATICS_APIKEY = <apikey>

Authenticate with external configuration

To use an external configuration file, see the related documentation in the Go SDK Core document about authentication.

Authenticate programmatically

To learn more about how to use programmatic authentication, see the related documentation in the Go SDK Core document about authentication.

Getting Started

A quick example to get you up and running with Schematics Go SDK service

package main

import (
	"encoding/json"
	"fmt"

	"github.com/IBM/go-sdk-core/v4/core"
	"github.com/IBM/schematics-go-sdk/schematicsv1"
)

func main() {

	schematicsService, _ := schematicsv1.NewSchematicsV1(&schematicsv1.SchematicsV1Options{
		URL: "https://schematics.cloud.ibm.com",
		Authenticator: &core.IamAuthenticator{
			URL:    "https://iam.cloud.ibm.com/identity/token",
			ApiKey: ". . . . . .",
		},
	})

	version, detailedResponse, err := schematicsService.GetSchematicsVersion(&schematicsv1.GetSchematicsVersionOptions{})

	if err != nil {
		fmt.Printf("Failed to get the version : %v and the response is %s", err, detailedResponse)
	}

	j, err := json.Marshal(version)
	fmt.Println("Schematics Version:", string(j))

	result, detailedResponse, err := schematicsService.ListWorkspaces(&schematicsv1.ListWorkspacesOptions{})

	if err != nil {
		fmt.Printf("Failed to list the workspaces : %v and the response is %s", err, detailedResponse)
	}

	w, err := json.Marshal(result)
	fmt.Println("Workspaces:", string(w))

}

Error handling

For sample code on handling errors, please see Schematics API docs.

Using the SDK

For general SDK usage information, please see this link

Questions

If you are having difficulties using this SDK or have a question about the IBM Cloud services, please ask a question at Stack Overflow.

Issues

If you encounter an issue with the project, you are welcome to submit a bug report. Before that, please search for similar issues. It's possible that someone has already reported the problem.

Open source @ IBM

Find more open source projects on the IBM Github Page

Contributing

See CONTRIBUTING.

License

This SDK project is released under the Apache 2.0 license. The license's full text can be found in LICENSE.

About

GO SDK for IBM Cloud Schematics service

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%