Skip to content

moira-alert/client-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go client for Moira

If you're new here, better check out our main README

Overview

This API client was generated by the go-swagger tool

Our current documentation is available on swaggerhub.

Installation

Add the following in import:

import "github.com/moira-alert/client-go"

Getting started

Initialize Moira client:

import (
	httptransport "github.com/go-openapi/runtime/client"
	"github.com/go-openapi/strfmt"
	"github.com/moira-alert/client-go/pkg/client"
)

func main() {
	config := client.DefaultTransportConfig().
		WithBasePath("api").
		WithHost("moira.example.com").
		WithSchemes([]string{"https"})

	transport := httptransport.New(config.Host, config.BasePath, config.Schemes)
	transport.Transport = newTransport() // Write a function here that creates an object that satisfies the http.RoundTripper interface

	client := client.New(transport, strfmt.Default)
}

Examples

Trigger

Get all Triggers:

client := client.New(transport, strfmt.Default)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

response, err := client.Trigger.GetAllTriggers(&trigger.GetAllTriggersParams{Context: ctx})

if err != nil {
	log.Fatal(err)
}

for _, trigger := range response.Payload.List {
	log.Println(trigger)
}

Contact

Create new contact:

client := client.New(transport, strfmt.Default)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

contactDto := models.DtoContact{
	Type: "telegram",
	Value: "@moira_team",
}

response, err := client.Contact.CreateNewContact(&contact.CreateNewContactParams{
	Contact: &contactDto,
	Context: ctx,
})

if err != nil {
	log.Fatal(err)
}

log.Println(response.Payload)

Subscription

Update existing subscription:

client := client.New(transport, strfmt.Default)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

subscriptionDto := &models.DtoSubscription{
	Tags: []string{"test"},
	Contacts: []string{"9fe937b0-721f-4b40-b849-ad1623f910a1"},
	Enabled: false,
}

response, err := client.Subscription.UpdateSubscription(&subscription.UpdateSubscriptionParams{
	Subscription: subscriptionDto,
	SubscriptionID: "2438f803-b278-47ee-91fb-e4345208dfde",
	Context: ctx,
})

if err != nil {
	log.Fatal(err)
}

log.Println(response.Payload)