client

package
v3.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package client provides a micro api client

Index

Constants

View Source
const (
	// Address for api
	DefaultAddress = "http://localhost:8080"
)

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) Handle

func (client *Client) Handle(service, endpoint string) http.Handler

Handle is a http handler for serving requests to the API

func (*Client) SetAddress

func (client *Client) SetAddress(a string)

SetAddress sets the api address

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 {
	// JWT token for authentication
	Token string
	// Address of the micro api
	Address string
	// set a request timeout
	Timeout time.Duration
}

Options of the Client

type Request

type Request struct {
	// eg. "helloworld"
	Service string `json:"service"`
	// eg. "Call"
	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
}

func (*Stream) Recv

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

func (*Stream) Send

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

Jump to

Keyboard shortcuts

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