service

package
v0.0.0-...-559b1bf Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrGeneric is a generic, internal error.
	ErrGeneric = "hive.internal.generic"
	// ErrNetwork is a internal network error.
	ErrNetwork = "hive.internal.network"
	// ErrRequest is a internal request error.
	ErrRequest = "hive.internal.request"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	ID     string
	Text   string
	Status int
}

Error stores service error IDs, texts and status codes.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Instance

func (e *Error) Instance(err error) *Error

Instance generates a new instance encapsuling the reference error.

func (*Error) Normalize

func (e *Error) Normalize() error

type Method

type Method interface {
	GetRequestType() reflect.Type
	GetResponseType() reflect.Type
	GetName() string
	HandleRequest(*Service, interface{}) (interface{}, *Error)
}

Method is a abstract interface representing a service method.

func NewContextualMethod

func NewContextualMethod(name string, requestType interface{}, responseType interface{}, handler func(*Service, interface{}) (interface{}, *Error)) Method

NewContextualMethod creates a new context-aware method handler.

func NewMethod

func NewMethod(name string, requestType interface{}, responseType interface{}, handler func(interface{}) (interface{}, *Error)) Method

NewMethod creates a new default method handler.

type Service

type Service struct {
	Name         string                 `json:"name"`
	DNSName      string                 `json:"dnsname"`
	Version      string                 `json:"version"`
	Methods      map[string]Method      `json:"methods"`
	Protocol     string                 `json:"protocol"`
	Socket       string                 `json:"socket"`
	Timeout      time.Duration          `json:"timeout"`
	Context      map[string]interface{} `json:"context"`
	ForwardLocal bool                   `json:"forwardLocal"`
	KnownErrors  map[string]Error       `json:"errors"`
}

Service is a microservice infrastructure abstraction.

func New

func New(name, version string) Service

New creates a new service.

func (Service) LogDebug

func (service Service) LogDebug(args ...interface{})

LogDebug logs an message of log level Debug.

func (Service) LogError

func (service Service) LogError(args ...interface{})

LogError logs an message of log level Error.

func (Service) LogInfo

func (service Service) LogInfo(args ...interface{})

LogInfo logs an message of log level Info.

func (Service) Match

func (service Service) Match(err *Error) *Error

Match generates a new user-friendly error instance.

func (Service) Register

func (service Service) Register(method Method)

Register a service method.

func (Service) RegisterError

func (service Service) RegisterError(e Error)

RegisterError registers a new error code.

func (Service) Run

func (service Service) Run()

Run the service.

func (Service) SThrow

func (service Service) SThrow(id string, text string) *Error

SThrow generates a new error code with the specific text.

func (Service) Send

func (service Service) Send(name string, request interface{}) (interface{}, *Error)

Send a request to the service.

func (Service) Throw

func (service Service) Throw(id string, err error) *Error

Throw generates a new debug-friendly error instance.

Jump to

Keyboard shortcuts

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