openmeter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

README

OpenMeter Go SDK

Install

go get github.com/openmeterio/openmeter

Usage

func main() {
    // Initialize OpenMeter client
    om, err := openmeter.NewClient("http://localhost:8888")
    if err != nil {
        panic(err.Error())
    }

    // Use OpenMeter client
    // ...
}

Documentation

Overview

Package openmeter provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version (devel) DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSwagger

func GetSwagger() (swagger *openapi3.T, err error)

GetSwagger returns the Swagger specification corresponding to the generated code in this file. The external references of Swagger specification are resolved. The logic of resolving external references is tightly connected to "import-mapping" feature. Externally referenced files must be embedded in the corresponding golang packages. Urls can be supported but this task was out of the scope.

func NewGetMetersByIdRequest

func NewGetMetersByIdRequest(server string, meterId string) (*http.Request, error)

NewGetMetersByIdRequest generates requests for GetMetersById

func NewGetMetersRequest

func NewGetMetersRequest(server string) (*http.Request, error)

NewGetMetersRequest generates requests for GetMeters

func NewGetValuesByMeterIdRequest

func NewGetValuesByMeterIdRequest(server string, meterId string, params *GetValuesByMeterIdParams) (*http.Request, error)

NewGetValuesByMeterIdRequest generates requests for GetValuesByMeterId

func NewIngestEventsRequest

func NewIngestEventsRequest(server string, body IngestEventsJSONRequestBody) (*http.Request, error)

NewIngestEventsRequest calls the generic IngestEvents builder with application/cloudevents+json body

func NewIngestEventsRequestWithBody

func NewIngestEventsRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewIngestEventsRequestWithBody generates requests for IngestEvents with any type of body

func PathToRawSpec

func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error)

Constructs a synthetic filesystem for resolving external references when loading openapi specifications.

Types

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func (*Client) GetMeters

func (c *Client) GetMeters(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) GetMetersById

func (c *Client) GetMetersById(ctx context.Context, meterId string, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) GetValuesByMeterId

func (c *Client) GetValuesByMeterId(ctx context.Context, meterId string, params *GetValuesByMeterIdParams, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) IngestEvents

func (c *Client) IngestEvents(ctx context.Context, body IngestEventsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) IngestEventsWithBody

func (c *Client) IngestEventsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

type ClientInterface

type ClientInterface interface {
	// IngestEvents request with any body
	IngestEventsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	IngestEvents(ctx context.Context, body IngestEventsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// GetMeters request
	GetMeters(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// GetMetersById request
	GetMetersById(ctx context.Context, meterId string, reqEditors ...RequestEditorFn) (*http.Response, error)

	// GetValuesByMeterId request
	GetValuesByMeterId(ctx context.Context, meterId string, params *GetValuesByMeterIdParams, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) GetMetersByIdWithResponse

func (c *ClientWithResponses) GetMetersByIdWithResponse(ctx context.Context, meterId string, reqEditors ...RequestEditorFn) (*GetMetersByIdResponse, error)

GetMetersByIdWithResponse request returning *GetMetersByIdResponse

func (*ClientWithResponses) GetMetersWithResponse

func (c *ClientWithResponses) GetMetersWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetMetersResponse, error)

GetMetersWithResponse request returning *GetMetersResponse

func (*ClientWithResponses) GetValuesByMeterIdWithResponse

func (c *ClientWithResponses) GetValuesByMeterIdWithResponse(ctx context.Context, meterId string, params *GetValuesByMeterIdParams, reqEditors ...RequestEditorFn) (*GetValuesByMeterIdResponse, error)

GetValuesByMeterIdWithResponse request returning *GetValuesByMeterIdResponse

func (*ClientWithResponses) IngestEventsWithBodyWithResponse

func (c *ClientWithResponses) IngestEventsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*IngestEventsResponse, error)

IngestEventsWithBodyWithResponse request with arbitrary body returning *IngestEventsResponse

func (*ClientWithResponses) IngestEventsWithResponse

func (c *ClientWithResponses) IngestEventsWithResponse(ctx context.Context, body IngestEventsJSONRequestBody, reqEditors ...RequestEditorFn) (*IngestEventsResponse, error)

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// IngestEvents request with any body
	IngestEventsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*IngestEventsResponse, error)

	IngestEventsWithResponse(ctx context.Context, body IngestEventsJSONRequestBody, reqEditors ...RequestEditorFn) (*IngestEventsResponse, error)

	// GetMeters request
	GetMetersWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetMetersResponse, error)

	// GetMetersById request
	GetMetersByIdWithResponse(ctx context.Context, meterId string, reqEditors ...RequestEditorFn) (*GetMetersByIdResponse, error)

	// GetValuesByMeterId request
	GetValuesByMeterIdWithResponse(ctx context.Context, meterId string, params *GetValuesByMeterIdParams, reqEditors ...RequestEditorFn) (*GetValuesByMeterIdResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type ErrResponse

type ErrResponse struct {
	Err error `json:"-"` // low-level runtime error

	StatusCode int    `json:"statusCode"`        // http response status code
	StatusText string `json:"status"`            // user-level status message
	AppCode    int64  `json:"code,omitempty"`    // application-specific error code
	Message    string `json:"message,omitempty"` // application-level error message, for debugging
}

ErrResponse renderer type for handling all sorts of errors. In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

type Error

type Error = ErrResponse

Error defines model for Error.

type Event

type Event = event.Event

Event CloudEvents Specification JSON Schema

type GetMetersByIdResponse

type GetMetersByIdResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *Meter
	JSON404      *Error
	JSONDefault  *Error
}

func ParseGetMetersByIdResponse

func ParseGetMetersByIdResponse(rsp *http.Response) (*GetMetersByIdResponse, error)

ParseGetMetersByIdResponse parses an HTTP response from a GetMetersByIdWithResponse call

func (GetMetersByIdResponse) Status

func (r GetMetersByIdResponse) Status() string

Status returns HTTPResponse.Status

func (GetMetersByIdResponse) StatusCode

func (r GetMetersByIdResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type GetMetersResponse

type GetMetersResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *[]Meter
	JSONDefault  *Error
}

func ParseGetMetersResponse

func ParseGetMetersResponse(rsp *http.Response) (*GetMetersResponse, error)

ParseGetMetersResponse parses an HTTP response from a GetMetersWithResponse call

func (GetMetersResponse) Status

func (r GetMetersResponse) Status() string

Status returns HTTPResponse.Status

func (GetMetersResponse) StatusCode

func (r GetMetersResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type GetValuesByMeterIdParams

type GetValuesByMeterIdParams struct {
	Subject *string `form:"subject,omitempty" json:"subject,omitempty"`

	// From Start date-time in RFC 3339 format.
	// Must be aligned with the window size.
	// Inclusive.
	From *time.Time `form:"from,omitempty" json:"from,omitempty"`

	// To End date-time in RFC 3339 format.
	// Must be aligned with the window size.
	// Inclusive.
	To *time.Time `form:"to,omitempty" json:"to,omitempty"`

	// WindowSize If not specified, a single usage aggregate will be returned for the entirety of the specified period for each subject and group.
	WindowSize *WindowSize `form:"windowSize,omitempty" json:"windowSize,omitempty"`
}

GetValuesByMeterIdParams defines parameters for GetValuesByMeterId.

type GetValuesByMeterIdResponse

type GetValuesByMeterIdResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *struct {
		Data       []MeterValue `json:"data"`
		WindowSize *WindowSize  `json:"windowSize,omitempty"`
	}
	JSONDefault *Error
}

func ParseGetValuesByMeterIdResponse

func ParseGetValuesByMeterIdResponse(rsp *http.Response) (*GetValuesByMeterIdResponse, error)

ParseGetValuesByMeterIdResponse parses an HTTP response from a GetValuesByMeterIdWithResponse call

func (GetValuesByMeterIdResponse) Status

Status returns HTTPResponse.Status

func (GetValuesByMeterIdResponse) StatusCode

func (r GetValuesByMeterIdResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type IngestEventsJSONRequestBody

type IngestEventsJSONRequestBody = Event

IngestEventsJSONRequestBody defines body for IngestEvents for application/cloudevents+json ContentType.

type IngestEventsResponse

type IngestEventsResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSONDefault  *Error
}

func ParseIngestEventsResponse

func ParseIngestEventsResponse(rsp *http.Response) (*IngestEventsResponse, error)

ParseIngestEventsResponse parses an HTTP response from a IngestEventsWithResponse call

func (IngestEventsResponse) Status

func (r IngestEventsResponse) Status() string

Status returns HTTPResponse.Status

func (IngestEventsResponse) StatusCode

func (r IngestEventsResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type Meter

type Meter = models.Meter

Meter defines model for Meter.

type MeterValue

type MeterValue = models.MeterValue

MeterValue defines model for MeterValue.

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type WindowSize

type WindowSize = models.WindowSize

WindowSize defines model for WindowSize.

Jump to

Keyboard shortcuts

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