client

package
v4.0.0-...-699247e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package client provides an api client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client enables generic calls to micro.

func NewClient

func NewClient(options *Options) *Client

NewClient returns a generic micro client that connects to live by default.

func (*Client) Call

func (client *Client) Call(service, endpoint string, request, response interface{}) error

Call enables you to access any endpoint of any service on Micro.

func (*Client) SetTimeout

func (client *Client) SetTimeout(d time.Duration)

SetTimeout sets the http client's timeout.

func (*Client) SetToken

func (client *Client) SetToken(t string)

SetToken sets the api auth token.

func (*Client) Stream

func (client *Client) Stream(service, endpoint string, request interface{}) (*Stream, error)

Stream enables the ability to stream via websockets.

type Options

type Options struct {
	// Token for authentication
	Token string
	// Address of the micro platform.
	// By default it connects to live. Change it or use the local flag
	// to connect to your local installation.
	Address string
	// Helper flag to help users connect to the default local address
	Local bool
	// set a timeout
	Timeout time.Duration
}

Options of the Client.

type Request

type Request struct {
	// eg. "go.micro.srv.greeter"
	Service string `json:"service"`
	// eg. "Say.Hello"
	Endpoint string `json:"endpoint"`
	// json and then base64 encoded body
	Body string `json:"body"`
}

Request is the request of the generic `api-client` call.

type Response

type Response struct {
	// json and base64 encoded response body
	Body string `json:"body"`
	// error fields. Error json example
	// {"id":"go.micro.client","code":500,"detail":"malformed method name: \"\"","status":"Internal Server Error"}
	Code   int    `json:"code"`
	ID     string `json:"id"`
	Detail string `json:"detail"`
	Status string `json:"status"`
}

Response is the response of the generic `api-client` call.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream is a websockets stream.

func (*Stream) Recv

func (s *Stream) Recv(v interface{}) error

Recv will receive a message from a stream and unmarshal it.

func (*Stream) Send

func (s *Stream) Send(v interface{}) error

Send will send a message into the stream.

Jump to

Keyboard shortcuts

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