Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/opslevel/opslevel-go
A Go client for interacting with OpsLevel
https://github.com/opslevel/opslevel-go
go graphql
Last synced: 10 days ago
JSON representation
A Go client for interacting with OpsLevel
- Host: GitHub
- URL: https://github.com/opslevel/opslevel-go
- Owner: OpsLevel
- License: mit
- Created: 2020-11-25T20:20:02.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-05T16:29:45.000Z (15 days ago)
- Last Synced: 2024-11-05T17:18:38.390Z (15 days ago)
- Topics: go, graphql
- Language: Go
- Homepage:
- Size: 2.27 MB
- Stars: 5
- Watchers: 7
- Forks: 13
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![Overall](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fapp.opslevel.com%2Fapi%2Fservice_level%2FOrfRqpiglK-WdxPAHJrUWzwYaweF_gDsmkSKWFYw9LU)](https://app.opslevel.com/services/opslevel_api_clients/maturity-report)
# opslevel-go
Package `opslevel` provides an OpsLevel API client implementation.
# Installation
`opslevel` requires Go version 1.8 or later.
```bash
go get -u github.com/opslevel/opslevel-go
```# Usage
Construct a client, specifying the [API token](https://app.opslevel.com/api_tokens). Then, you can use it to make GraphQL queries and mutations.
```go
client := opslevel.NewGQLClient(opslevel.SetAPIToken("XXX_API_TOKEN_XXX"))
// Use client...
```You can validate the client can successfully talk to the OpsLevel API.
```go
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:
```go
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:
```go
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:
```go
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:
```go
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:
```go
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](https://github.com/hasura/go-graphql-client).