restlib

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: Unlicense Imports: 6 Imported by: 0

README

RestLIB

Minimal interface for standardizing Rest client integrations in my Golang projects

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(c APIClient, path string, request *Message, response *Message) (err error)

Call is a default implementation of the APIClient.Call method

Types

type APIClient

type APIClient interface {
	// MessageType retrieves the type of messages sent and received over the API
	MessageType() MessageType

	// Host retrieves the API host server
	Host() *url.URL

	// Call will send the message to the API host, and expect a response message in return
	Call(path string, request *Message, response *Message) (err error)
}

type Message

type Message struct {
	// Method tells which method to use when sending request
	Method string

	// Status is a representation of eg. http status code in responses
	Status int

	// Header is a map of Message headers
	Header http.Header

	// Body is the message body object
	// the message body is de-serialized at retrieval and serialized before sending request
	Body interface{}
}

type MessageType

type MessageType interface {
	// ContentType retrieves the MIME-type of the message body
	ContentType() string

	// Serializer retrieves the message serializer to use
	Serializer() Serializer
}

type Serializer

type Serializer interface {
	// Marshal will convert the message in to a byte slice for sending in request
	Marshal(*Message) ([]byte, error)

	// Unmarshal will convert a raw message into the provided pointer to a Message interfaced struct
	Unmarshal([]byte, *Message) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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