service

package
v0.0.0-...-a2da514 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FuncDef

type FuncDef struct {
	Name   string     `json:"name"`
	Type   string     `json:"type"`
	Values []*FuncDef `json:"values"`
	// contains filtered or unexported fields
}

func (*FuncDef) TypeOf

func (f *FuncDef) TypeOf() reflect.Type

type FuncOption

type FuncOption func(*FuncOptions)

type FuncOptions

type FuncOptions struct {
	Name    string
	Version semver.Version
	Labels  map[string]string
	Tags    []string
}

type Function

type Function interface {
	Name() string
	Request() *FuncDef
	Response() *FuncDef
	Options() *FuncOptions
}

func NewFunction

func NewFunction(rf interface{}, opts ...FuncOption) (Function, error)

type FunctionInvocation

type FunctionInvocation func(rf reflect.Type, opts ...FuncOption) (Function, error)

type Handler

type Handler interface {
	Name() string
	Options() *HandlerOptions
	Methods() []Method
	Call(req Request, resp interface{}, opts ...HandlerOption) error
	NewRequest(string, ...RequestOption) Request
	Meta() map[string]map[string]string
}

func NewHandler

func NewHandler(v interface{}, opts ...HandlerOption) Handler

type HandlerInvocation

type HandlerInvocation func(v interface{}, opts ...HandlerOption) Handler

type HandlerOption

type HandlerOption func(*HandlerOptions)

func HandlerName

func HandlerName(n string) HandlerOption

type HandlerOptions

type HandlerOptions struct {
	Name string
	Meta map[string]map[string]string
	Type string
}

type Method

type Method interface {
	Name() string
	Request() *MethodDef
	Response() *MethodDef
	Options() *MethodOptions
}

func NewMethod

func NewMethod(rm reflect.Method, opts ...MethodOption) (Method, error)

type MethodDef

type MethodDef struct {
	Name   string       `json:"name"`
	Type   string       `json:"type"`
	Values []*MethodDef `json:"arguments"`
	// contains filtered or unexported fields
}

func (*MethodDef) TypeOf

func (m *MethodDef) TypeOf() reflect.Type

type MethodInvocation

type MethodInvocation func(rm reflect.Method, opts ...MethodOption) (Method, error)

type MethodOption

type MethodOption func(*MethodOptions)

type MethodOptions

type MethodOptions struct {
	Name    string
	Version semver.Version

	Labels map[string]string
	Tags   []string
}

type Option

type Option func(*Options)

func Connector

func Connector(c connector.Connector) Option

func Name

func Name(n string) Option

func Namespace

func Namespace(ns string) Option

func Version

func Version(v string) Option

func WithLabel

func WithLabel(k, v string) Option

func WithLabels

func WithLabels(lab map[string]string) Option

func WithTag

func WithTag(tag ...string) Option

type Options

type Options struct {
	Name      string
	Namespace string
	Version   semver.Version
	Labels    map[string]string
	Tags      []string

	Connectors map[string]connector.Connector
	Meta       metadata.Metadata
}

type Request

type Request interface {
	Context() context.Context
	Service() string
	Handler() string
	Method() string
	Body() RequestBody
	Headers() map[string]string
}

Request describes the Service Call and contains the Body and Headers

func NewRequest

func NewRequest(ctx context.Context, svc, hndlr, meth string, hdrs map[string]string, body RequestBody) Request

NewRequest returns a Request with functional argument construction

func NewRequestFromOptions

func NewRequestFromOptions(opts ...RequestOption) Request

NewRequestFromOptions returns a new Request by declaritive construction

type RequestBody

type RequestBody interface {
	ContentType() string
	Interface() interface{}
	Raw() ([]byte, error)
	Bind(interface{}) error
}

RequestBody interface allows interaction with the raw request or Bind will map it onto a struct

func NewRequestBody

func NewRequestBody(ct string, body interface{}) RequestBody

NewRequestBody returns a RequestBody with a specified Content-Type and arbitrary Content

type RequestExtension

type RequestExtension func(Request) Request

RequestExtension is middleware for Requests

type RequestOption

type RequestOption func(*RequestOptions)

RequestOption acts as a setter for RequestOptions

func WithBody

func WithBody(ctype string, body interface{}) RequestOption

WithBody sets the body of the request

func WithContext

func WithContext(ctx context.Context) RequestOption

WithContext sets the Context of the Request

func WithHeaders

func WithHeaders(hdrs map[string]string) RequestOption

WithHeaders sets the Headers of the Request

type RequestOptions

type RequestOptions struct {
	Context context.Context
	Service string
	Handler string
	Method  string
	Body    RequestBody
	Headers map[string]string
}

RequestOptions allows for declaritive construction of a Request

type Service

type Service interface {
	Name() string
	Options() *Options
	Configure(...Option)
	Handle(Handler, ...HandlerOption) error
	Handler(string) Handler
	Handlers() []string
	Usage() string
	Call(req Request, resp interface{}) error
}

Service interface allows registration of one or many handlers and provides a Call method to invoke methods on those handlers

func NewService

func NewService(h interface{}, opts ...Option) Service

NewService takes an initial handler (service wouldn't do much without one) and a set of options and returns a Service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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