Giter Club home page Giter Club logo

oci-go-sdk's Introduction

Oracle Cloud Infrastructure Golang SDK

wercker status

This is the Go SDK for Oracle Cloud Infrastructure. This project is open source and maintained by Oracle Corp. The home page for the project is here.

WARNING:: To avoid automatically consuming breaking changes if we have to rev the major version of the Go SDK, please consider using the Go dependency management tool, or vendoring the SDK. This will allow you to pin to a specific version of the Go SDK in your project, letting you control how and when you move to the next major version.

Dependencies

Installing

Use the following command to install this SDK:

go get -u github.com/oracle/oci-go-sdk

Alternatively you can git clone this repo.

Working with the Go SDK

To start working with the Go SDK, you import the service package, create a client, and then use that client to make calls.

Configuring

Before using the SDK, set up a config file with the required credentials. See SDK and Tool Configuration for instructions.

Once a config file has been setup, call common.DefaultConfigProvider() function as follows:

// Import necessary packages
import (
   "github.com/oracle/oci-go-sdk/common"
   "github.com/oracle/oci-go-sdk/identity" // Identity or any other service you wish to make requests to
)

//...

configProvider := common.DefaultConfigProvider()

Or, to configure the SDK programmatically instead, implement the ConfigurationProvider interface shown below:

// ConfigurationProvider wraps information about the account owner
type ConfigurationProvider interface {
   KeyProvider
   TenancyOCID() (string, error)
   UserOCID() (string, error)
   KeyFingerprint() (string, error)
   Region() (string, error)
}

Making a request

To make a request to an OCI service, create a client for the service and then use the client to call a function from the service.

  • Creating a client: All packages provide a function to create clients, using the naming convention New<ServiceName>ClientWithConfigurationProvider, such as NewVirtualNetworkClientWithConfigurationProvider or NewIdentityClientWithConfigurationProvider. To create a new client, pass a struct that conforms to the ConfigurationProvider interface, or use the DefaultConfigProvider() function in the common package.

For example:

config := common.DefaultConfigProvider()
client, err := identity.NewIdentityClientWithConfigurationProvider(config)
if err != nil { 
     panic(err)
}
  • Making calls: After successfully creating a client, requests can now be made to the service. Generally all functions associated with an operation accept context.Context and a struct that wraps all input parameters. The functions then return a response struct that contains the desired data, and an error struct that describes the error if an error occurs.

For example:

id := "your_group_id"
response, err := client.GetGroup(context.Background(), identity.GetGroupRequest{GroupId:&id})
if err != nil {
	//Something happened
	panic(err)
}
//Process the data in response struct
fmt.Println("Group's name is:", response.Name)

Organization of the SDK

The oci-go-sdk contains the following:

  • Service packages: All packages except common and any other package found inside cmd. These packages represent the Oracle Cloud Infrastructure services supported by the Go SDK. Each package represents a service. These packages include methods to interact with the service, structs that model input and output parameters, and a client struct that acts as receiver for the above methods.

  • Common package: Found in the common directory. The common package provides supporting functions and structs used by service packages. Includes HTTP request/response (de)serialization, request signing, JSON parsing, pointer to reference and other helper functions. Most of the functions in this package are meant to be used by the service packages.

  • cmd: Internal tools used by the oci-go-sdk.

Examples

Examples can be found here

Documentation

Full documentation can be found on the godocs site.

Help

Contributing

oci-go-sdk is an open source project. See CONTRIBUTING for details.

Oracle gratefully acknowledges the contributions to oci-go-sdk that have been made by the community.

License

Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.

This SDK and sample is dual licensed under the Universal Permissive License 1.0 and the Apache License 2.0.

See LICENSE for more details.

Changes

See CHANGELOG.

Known Issues

You can find information on any known issues with the SDK here and under the Issues tab of this project's GitHub repository.

Building and testing

Dev dependencies

  • Install Testify with the command:
go get github.com/stretchr/testify
  • Install go lint with the command:
go get -u github.com/golang/lint/golint

Build

Building is provided by the make file at the root of the project. To build the project execute.

make build

To run the tests:

make test

oci-go-sdk's People

Contributors

drewwells avatar eginez avatar jasonyin avatar jastanko avatar jhorwit2 avatar jodoglevy avatar kohashim avatar owainlewis avatar scotmoor avatar templecloud avatar

Watchers

 avatar  avatar

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.