gorpc

package module
v0.0.0-...-5872c39 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: GPL-2.0 Imports: 9 Imported by: 0

README

gorpc

GoDoc Build Status

Framework for building Go RPC server with versioned handlers and autogenerated documentation without code generation. You just write code and don't think about transport and documentation.

Idea

You write handlers in native Go (with some restrictions), register them in HandlersManager, add transport implementation and documentation's UI to your application and it's all, now you have RPC API with documentation. Documentation will update automatically if you add or change handlers.

Packages

  • github.com/sergei-svistunov/gorpc: framework's core
  • github.com/sergei-svistunov/gorpc/transport/http_json: transport's implementation over HTTP with serialization into JSON
  • github.com/sergei-svistunov/gorpc/swagger_ui: Swagger UI in one Go library

Documentation

Index

Constants

View Source
const (
	ErrorInParameters = iota
	ErrorReturnedFromCall
	ErrorInvalidMethod
	ErrorWriteResponse
	ErrorUnknown
	ErrorPanic
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallHandlerError

type CallHandlerError struct {
	Type int
	Err  error
}

func (*CallHandlerError) Error

func (e *CallHandlerError) Error() string

func (*CallHandlerError) ErrorCode

func (e *CallHandlerError) ErrorCode() string

func (*CallHandlerError) UserMessage

func (e *CallHandlerError) UserMessage() string

type HandlerError

type HandlerError struct {
	UserMessage string
	Err         error
	Code        string
}

func (*HandlerError) Error

func (e *HandlerError) Error() string

type HandlerParameter

type HandlerParameter struct {
	Name        string
	Description string
	Key         string
	Path        []string
	RawType     reflect.Type
	IsRequired  bool

	Fields []HandlerParameter
	// contains filtered or unexported fields
}

func (*HandlerParameter) GetKey

func (p *HandlerParameter) GetKey() string

type HandlerVersion

type HandlerVersion *handlerVersion

type HandlersManager

type HandlersManager struct {
	// contains filtered or unexported fields
}

func NewHandlersManager

func NewHandlersManager(handlersPath string, callbacks HandlersManagerCallbacks) *HandlersManager

func (*HandlersManager) CallHandler

func (hm *HandlersManager) CallHandler(ctx context.Context, handler HandlerVersion, params reflect.Value) (interface{}, *CallHandlerError)

func (*HandlersManager) FindHandler

func (hm *HandlersManager) FindHandler(path string, version int) HandlerVersion

FindHandler returns a handler by given non-versioned path and given version number

func (*HandlersManager) FindHandlerByRoute

func (hm *HandlersManager) FindHandlerByRoute(route string) HandlerVersion

FindHandlerByRoute returns a handler by fully qualified route to that particular version of the handler

func (*HandlersManager) GetHandlerInfo

func (hm *HandlersManager) GetHandlerInfo(path string) *handlerInfo

func (*HandlersManager) GetHandlersPaths

func (hm *HandlersManager) GetHandlersPaths() []string

func (*HandlersManager) MustRegisterHandler

func (hm *HandlersManager) MustRegisterHandler(h IHandler)

func (*HandlersManager) MustRegisterHandlers

func (hm *HandlersManager) MustRegisterHandlers(handlers ...IHandler)

func (*HandlersManager) Pkg

func (hm *HandlersManager) Pkg() string

func (*HandlersManager) RegisterHandler

func (hm *HandlersManager) RegisterHandler(h IHandler) error

func (*HandlersManager) RegisterHandlers

func (hm *HandlersManager) RegisterHandlers(handlers ...IHandler) error

func (*HandlersManager) UnmarshalParameters

func (*HandlersManager) UnmarshalParameters(ctx context.Context, handler HandlerVersion,
	handlerParameters IHandlerParameters) (reflect.Value, error)

type HandlersManagerCallbacks

type HandlersManagerCallbacks struct {
	// OnHandlerRegistration will be called only one time for each handler version while handler registration is in progress
	OnHandlerRegistration func(path string, method reflect.Method) (extraData interface{})

	// OnError will be called if any error occurs while CallHandler() method is in processing
	OnError func(ctx context.Context, err error)

	// OnSuccess will be called if CallHandler() method is successfully finished
	OnSuccess func(ctx context.Context, result interface{})

	// AppendInParams will be called for each handler call and can append extra parameters to params
	AppendInParams func(ctx context.Context, preparedParams []reflect.Value, extraData interface{}) (context.Context, []reflect.Value, error)
}

type IHandler

type IHandler interface {
	Caption() string
	Description() string
}

type IHandlerParameters

type IHandlerParameters interface {
	Fork(m map[string]interface{}) interface{}
	Parse() error

	IsExists([]string, string) bool

	GetString([]string, string) (string, error)

	GetBool([]string, string) (bool, error)

	GetUint([]string, string) (uint, error)
	GetByte([]string, string) (byte, error)
	GetUint8([]string, string) (uint8, error)
	GetUint16([]string, string) (uint16, error)
	GetUint32([]string, string) (uint32, error)
	GetUint64([]string, string) (uint64, error)

	GetInt([]string, string) (int, error)
	GetInt8([]string, string) (int8, error)
	GetInt16([]string, string) (int16, error)
	GetInt32([]string, string) (int32, error)
	GetInt64([]string, string) (int64, error)

	GetFloat32([]string, string) (float32, error)
	GetFloat64([]string, string) (float64, error)

	TraverseSlice(path []string, name string, h func(i int, v interface{}) error) (bool, error)
	TraverseMap(path []string, name string, h func(k string, v interface{}) error) (bool, error)
}

Jump to

Keyboard shortcuts

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