svc

package
v0.0.0-...-08046e1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrProtocolExtraction

type ErrProtocolExtraction struct {
	Protocol string
}

ErrProtocolExtraction is returned when we fail to extract a protocol from a request or fail to parse its JSON.

func (ErrProtocolExtraction) Error

func (e ErrProtocolExtraction) Error() string

type Req

type Req map[string]*json.RawMessage

Req is the structure used to make a request to a service

func (Req) Extract

func (h Req) Extract(
	protocol string,
	data interface{},
) error

Extract extracts a protocol from a request

func (Req) ExtractAll

func (h Req) ExtractAll(
	protocols map[string]interface{},
) error

ExtractAll extracts a set of protocols given by the keys of `protocols` from `h`. Protocols are considered optional if they end with a '?' character. For example, the following code would read the protocol "foo" into the variable `a` and the protocol "bar" into the variable `b` if the request contains that protocol. If the "bar" protocol is not specified, `b` will retain its original value "optional".

a := "required"
b := "optional"
err := req.ExtractAll(map[string]interface{}{
  "foo":  &a,
  "bar?": &b,
})

This function returns an error if we fail to extract any required protocol.

type Resp

type Resp map[string]*json.RawMessage

Resp is the structure used to respond to a request

func (Resp) Extract

func (h Resp) Extract(
	protocol string,
	data interface{},
) error

Extract extracts a protocol from a response

Jump to

Keyboard shortcuts

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