go-sdk

module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2025 License: Apache-2.0

README

OpenSLO light theme

OpenSLO SDK for the Go programming language.

⚠️ The SDK is in active development and awaits its official, v1 release. We expect breaking API changes to be introduced freely.


Installation

To add the latest version to your Go module run:

go get github.com/OpenSLO/go-sdk

Usage

package pkg_test

import (
	"bytes"
	"os"

	v1 "github.com/OpenSLO/go-sdk/pkg/openslo/v1"
	"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)

const serviceDefinition = `
apiVersion: openslo/v1
kind: Service
metadata:
  name: web-app
  displayName: React Web Application
spec:
  description: Web application built in React
`

func Example() {
	// Decode the Service.
	objects, err := openslosdk.Decode(bytes.NewBufferString(serviceDefinition), openslosdk.FormatYAML)
	if err != nil {
		panic(err)
	}

	// Define Data Source in code.
	dataSource := v1.NewDataSource(
		v1.Metadata{
			Name: "prometheus",
			Labels: v1.Labels{
				"env": {"prod"},
			},
		},
		v1.DataSourceSpec{
			Description:       "Production Prometheus",
			Type:              "Prometheus",
			ConnectionDetails: []byte(`[{"url":"http://prometheus.example.com"}]`),
		},
	)

	// Add Data Source to objects.
	objects = append(objects, dataSource)

	// Validate the objects.
	if err = openslosdk.Validate(objects...); err != nil {
		panic(err)
	}

	// Write objects to stdout in JSON format.
	err = openslosdk.Encode(os.Stdout, openslosdk.FormatJSON, objects...)
	if err != nil {
		panic(err)
	}

	// Output:
	// [
	//   {
	//     "apiVersion": "openslo/v1",
	//     "kind": "Service",
	//     "metadata": {
	//       "name": "web-app",
	//       "displayName": "React Web Application"
	//     },
	//     "spec": {
	//       "description": "Web application built in React"
	//     }
	//   },
	//   {
	//     "apiVersion": "openslo/v1",
	//     "kind": "DataSource",
	//     "metadata": {
	//       "name": "prometheus",
	//       "labels": {
	//         "env": [
	//           "prod"
	//         ]
	//       }
	//     },
	//     "spec": {
	//       "description": "Production Prometheus",
	//       "type": "Prometheus",
	//       "connectionDetails": [
	//         {
	//           "url": "http://prometheus.example.com"
	//         }
	//       ]
	//     }
	//   }
	// ]
}

Contributing

Checkout contributing guidelines.

Directories

Path Synopsis
assert
Package assert provides utility functions for testing which help assert certain conditions are met.
Package assert provides utility functions for testing which help assert certain conditions are met.
pkg
openslo
Package openslo defines the OpenSLO specification general definitions.
Package openslo defines the OpenSLO specification general definitions.
openslo/v1
Package v1 contains the OpenSLO specification version v1alpha definitions.
Package v1 contains the OpenSLO specification version v1alpha definitions.
openslo/v1alpha
Package v1alpha defines the OpenSLO specification version v1alpha definitions.
Package v1alpha defines the OpenSLO specification version v1alpha definitions.
openslo/v2alpha
Package v2alpha contains the OpenSLO specification version v2alpha definitions.
Package v2alpha contains the OpenSLO specification version v2alpha definitions.
openslosdk
Package openslosdk provides utilities for working with openslo.Object.
Package openslosdk provides utilities for working with openslo.Object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL