Code Monkey home page Code Monkey logo

opslevel-go's Introduction

License Made With Go Release Issues Contributors Activity CodeCov Dependabot Go Reference

The OpsLevel Gopher

Overall

opslevel-go

Package opslevel provides an OpsLevel API client implementation.

Installation

opslevel requires Go version 1.8 or later.

go get -u github.com/opslevel/opslevel-go

Usage

Construct a client, specifying the API token. Then, you can use it to make GraphQL queries and mutations.

client := opslevel.NewGQLClient(opslevel.SetAPIToken("XXX_API_TOKEN_XXX"))
// Use client...

You can validate the client can successfully talk to the OpsLevel API.

client := opslevel.NewClient("XXX_API_TOKEN_XXX")
if err := client.Validate(); err != nil {
	panic(err)
}

Every resource (IE: service, lifecycle, tier, etc.) in OpsLevel API has a corresponding data structure in go as well as the graphql query & mutation inputs. Additionally, there are also some helper functions that use native go types like string and []string to make it easier to work with. The following are a handful of examples:

Find a service given an alias and print the owning team name:

foundService, foundServiceErr := client.GetServiceWithAlias("MyCoolService")
if foundServiceErr != nil {
	panic(foundServiceErr)
}
fmt.Println(foundService.Owner.Name)

Create a new service in OpsLevel and print the ID:

serviceCreateInput := opslevel.ServiceCreateInput{
	Name:        "MyCoolService",
	Product:     "MyProduct",
	Description: "The Coolest Service",
	Language:    "go",
}
newService, newServiceErr := client.CreateService(serviceCreateInput)
if newServiceErr != nil {
	panic(newServiceErr)
}
fmt.Println(newService.Id)

Assign the tag {"hello": "world"} to our newly created service and print all the tags currently on it:

allTagsOnThisService, assignTagsErr := client.AssignTags(newService.Id, map[string]string{"hello": "world"})
if assignTagsErr != nil {
	panic(assignTagsErr)
}
for _, tagOnService := range allTagsOnThisService {
	fmt.Printf("Tag '{%s : %s}'", tagOnService.Id, tagOnService.Value)
}

List all the tags for a service:

myService, foundServiceErr := client.GetServiceWithAlias("MyCoolService")
if foundServiceErr != nil {
	panic(foundServiceErr)
}
tags, getTagsErr := myService.GetTags(client, nil)
if getTagsErr != nil {
	panic(getTagsErr)
}
for _, tag := range tags {
	fmt.Printf("Tag '{%s : %s}'\n", tag.Key, tag.Value)
}

Build a lookup table of teams:

func GetTeams(client *opslevel.Client) (map[string]opslevel.Team, error) {
	teams := make(map[string]opslevel.Team)
	data, dataErr := client.ListTeams()
	if dataErr != nil {
		return teams, dataErr
	}
	for _, team := range data {
		teams[string(team.Alias)] = team
	}
	return teams, nil
}

Advanced Usage

The client also exposes functions Query and Mutate for doing custom query or mutations. We are running on top of this go graphql library.

opslevel-go's People

Contributors

rocktavious avatar davidbloss avatar eochoa260 avatar opslevel-ops avatar dependabot[bot] avatar matthewbrahms avatar taimoorgit avatar maxim-opslevel avatar opslevel-eric avatar jasonopslevel avatar alan-opslevel avatar derek-lai- avatar dougedey avatar george-e-shaw-iv avatar rauhut avatar eapache avatar rene00 avatar terryopsleveltest 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.