Git Product home page Git Product logo

client-go's Introduction

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.skbkontur.ru").
		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)

client-go's People

Contributors

almostinf avatar kissken avatar tetrergeru avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.