https://github.com/opslevel/opslevel-go
A Go client for interacting with OpsLevel
https://github.com/opslevel/opslevel-go
go graphql
Last synced: 8 months 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 (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-09-29T13:19:00.000Z (8 months ago)
- Last Synced: 2025-09-29T15:24:06.805Z (8 months ago)
- Topics: go, graphql
- Language: Go
- Homepage:
- Size: 2.55 MB
- Stars: 6
- Watchers: 9
- Forks: 13
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README

[](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/v2025
```
# 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.NewGQLClient(opslevel.SetAPIToken("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.GetService("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",
Description: opslevel.RefOf("The Coolest Service"),
Language: opslevel.RefOf("go"),
OwnerAlias: opslevel.RefOf("team-platform"),
}
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(string(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.GetService("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(nil)
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).