rest

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToInt64 added in v1.3.0

func BytesToInt64(bytes []byte) int64

BytesToInt64 конвертирует срез байтов в int64

func Int64ToBytes added in v1.3.0

func Int64ToBytes(num int64, byteCount int) []byte

Int64ToBytes упаковывает int64 в срез байтов заданной длины

func NewTemporaryFile added in v1.3.0

func NewTemporaryFile(size int64, r io.Reader) (IReadCloserLen, IErrorArgs)

func ReadRequestStream added in v1.3.0

func ReadRequestStream(r io.Reader) (*RequestStream, IErrorArgs)

Types

type Command

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

func NewCommand

func NewCommand(validator IValidator, executer IExecuter) *Command

func (*Command) Execute

func (s *Command) Execute(r IRequestIn) IRequestOut

func (*Command) Validate

func (s *Command) Validate(r IRequestIn) IRequestOut

type Error

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

func (*Error) Args added in v1.1.0

func (s *Error) Args() json.Map

func (*Error) Error

func (s *Error) Error() string

func (*Error) Map

func (s *Error) Map() json.Map

func (*Error) Name added in v1.1.0

func (s *Error) Name() string

type Executer

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

func NewExecuter

func NewExecuter(method func(r IRequestIn) IRequestOut) *Executer

func (*Executer) Execute

func (s *Executer) Execute(r IRequestIn) IRequestOut

type Field added in v1.1.0

type Field struct {
	Name  string
	Names []any
}

Field реализует ...

type FieldList added in v1.1.0

type FieldList []*Field

func (FieldList) Field added in v1.1.0

func (s FieldList) Field(name string) (*Field, bool)

type IApplication added in v1.1.0

type IApplication interface {
	Executer(r IRequestIn) (IExecuter, bool)
}

type IApplicationStream added in v1.3.0

type IApplicationStream interface {
	IApplication
	Connect() chan<- IStream
}

type ICommand

type ICommand interface {
	IValidator
	IExecuter
}

type IErrorArgs

type IErrorArgs interface {
	Name() string
	Args() json.Map
	Error() string
	Map() json.Map
}

func ErrorFiled added in v1.1.0

func ErrorFiled(field, message string) IErrorArgs

func ErrorMessage added in v1.2.0

func ErrorMessage(name, text string) IErrorArgs

func Fields added in v1.1.0

func Fields(obj any, files RequestFiles, names ...any) (json.Map, IErrorArgs)

Fields позволяет получить значения объекта в json

func NewError

func NewError(name string, args json.Map) IErrorArgs

func ReadBuf added in v1.3.0

func ReadBuf(r io.Reader, size int, field string) ([]byte, IErrorArgs)

func ReadBufSize added in v1.3.0

func ReadBufSize(r io.Reader, lenSize int, field string) ([]byte, IErrorArgs)

func ReadByte added in v1.3.0

func ReadByte(r io.Reader, field string, result *byte) IErrorArgs

func ReadInt64 added in v1.3.0

func ReadInt64(r io.Reader, size int, field string, result *int64) IErrorArgs

func ReadString added in v1.3.0

func ReadString(r io.Reader, lenSize int, field string, result *string) IErrorArgs

func Serialize added in v1.2.0

func Serialize(from json.Map, to any) IErrorArgs

func WriteBuf added in v1.3.0

func WriteBuf(w io.Writer, buf []byte, field string) IErrorArgs

func WriteBufSize added in v1.3.0

func WriteBufSize(w io.Writer, val []byte, lenSize int, field string) IErrorArgs

func WriteByte added in v1.3.0

func WriteByte(w io.Writer, val byte, field string) IErrorArgs

func WriteInt64 added in v1.3.0

func WriteInt64(w io.Writer, val int64, size int, field string) IErrorArgs

func WriteString added in v1.3.0

func WriteString(w io.Writer, val, field string, lenSize int) IErrorArgs

type IExecuter

type IExecuter interface {
	Execute(r IRequestIn) IRequestOut
}

type IFielderPost added in v1.3.3

type IFielderPost interface {
	RestFieldsPost(result json.Map, files map[string]IReadCloserLen, names FieldList)
}

IFielder реадизует интерфейс завершения формирования полей объекта в "ручном" режиме. RestFields будет вызван после завершения автматического формирования полей объекта result - массив с полями, сформированными автоматически, в него можно вносить правки files - глобальный массив файловых дескрипторов, который будет передан в ответе клиенту

type IOwner added in v1.3.0

type IOwner interface {
	IsStream() bool
}

type IReadCloser added in v1.3.0

type IReadCloser interface {
	io.ReadCloser
	Len() int64
}

type IReadCloserLen added in v1.3.0

type IReadCloserLen interface {
	io.ReadCloser
	Len() int64
}

func NewReadCloserLen added in v1.3.0

func NewReadCloserLen(rc io.ReadCloser, len int64) IReadCloserLen

type IRequest added in v1.2.0

type IRequest interface {
	RType() RequestType
	RCommand() string
	RData() json.Map
	RFiles() RequestFiles
	RFile(string) (IReadCloserLen, bool)
	RClose()
	Fields(any, RequestFiles) (json.Map, IErrorArgs)
}

type IRequestIn added in v1.3.0

type IRequestIn interface {
	IRequest
	Auth() json.Map
	SetAuth(json.Map)
	GenerateToken(data json.Map, expire int64) (string, error)
	ROwner() IOwner
	RCore() any
	OutSuccess(data json.Map, files RequestFiles) IRequestOut
	OutError(err IErrorArgs) IRequestOut
	ClientData(key string) (any, bool)
	SetClientData(key string, data any)
}

type IRequestOut added in v1.3.0

type IRequestOut interface {
	IRequest
	Write(io.Writer) IErrorArgs
}

type IRestConverter added in v1.3.3

type IRestConverter interface {
	RestFrom(any) IErrorArgs
}

type IRestFielder added in v1.3.3

type IRestFielder interface {
	RestFields(fieldName string, names ...any) (any, IErrorArgs)
}

type IServer added in v1.3.0

type IServer interface {
	Addr() string
	Secret() []byte
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
	Listen(timeout time.Duration) error
	TokenGenerate(m json.Map, expire int64) (string, error)
	Close() error
	Context() context.Context
}

func NewServer added in v1.3.0

func NewServer(addr string, secret []byte) IServer

type IStream added in v1.3.0

type IStream interface {
	SetAuth(json.Map)
	Auth() json.Map
	SetClientData(key string, val any)
	ClientData(key string) (any, bool)
	Context() context.Context
	SendMessage(IRequestOut) (<-chan *RequestStream, error)
}

type IValidator

type IValidator interface {
	Validate(r IRequestIn) IRequestOut
}

type Request

type Request struct {
	Type    RequestType
	Command string
	Data    json.Map
	Files   RequestFiles
}

func (*Request) Fields added in v1.3.0

func (s *Request) Fields(obj any, files RequestFiles) (json.Map, IErrorArgs)

func (*Request) RClose added in v1.3.0

func (s *Request) RClose()

func (*Request) RCommand added in v1.3.0

func (s *Request) RCommand() string

func (*Request) RData added in v1.3.0

func (s *Request) RData() json.Map

func (*Request) RFile added in v1.3.0

func (s *Request) RFile(name string) (IReadCloserLen, bool)

func (*Request) RFiles added in v1.3.0

func (s *Request) RFiles() RequestFiles

func (*Request) RType added in v1.3.0

func (s *Request) RType() RequestType

type RequestFiles added in v1.3.0

type RequestFiles map[string]IReadCloserLen

type RequestIn added in v1.3.0

type RequestIn struct {
	IRequest
	Owner          IOwner
	Core           any
	GeneratorToken TokenGenerateMethod
}

func (*RequestIn) Auth added in v1.3.0

func (s *RequestIn) Auth() json.Map

func (*RequestIn) ClientData added in v1.3.0

func (s *RequestIn) ClientData(key string) (any, bool)

func (*RequestIn) GenerateToken added in v1.3.0

func (s *RequestIn) GenerateToken(data json.Map, expire int64) (string, error)

func (*RequestIn) RCore added in v1.3.0

func (s *RequestIn) RCore() any

func (*RequestIn) ROwner added in v1.3.0

func (s *RequestIn) ROwner() IOwner

func (*RequestIn) SetAuth added in v1.3.0

func (s *RequestIn) SetAuth(auth json.Map)

func (*RequestIn) SetClientData added in v1.3.0

func (s *RequestIn) SetClientData(key string, data any)

type RequestStream added in v1.3.0

type RequestStream struct {
	ID      int64
	Timeout time.Time
	*Request
}

func NewRequestStream added in v1.3.0

func NewRequestStream(timeout time.Time, req *Request) *RequestStream

func (*RequestStream) Write added in v1.3.0

func (s *RequestStream) Write(w io.Writer) IErrorArgs

type RequestType added in v1.3.0

type RequestType byte
const (
	RequestTypeIn RequestType = iota
	RequestTypeOut
	RequestTypeEvent
)

type ResponseEmpty added in v1.3.0

type ResponseEmpty struct{}

func (*ResponseEmpty) Close added in v1.3.0

func (s *ResponseEmpty) Close()

func (*ResponseEmpty) FileSet added in v1.3.0

func (s *ResponseEmpty) FileSet(name string, file IReadCloserLen)

func (*ResponseEmpty) IsError added in v1.3.0

func (s *ResponseEmpty) IsError() bool

func (*ResponseEmpty) KeySet added in v1.3.0

func (s *ResponseEmpty) KeySet(key string, val any)

func (*ResponseEmpty) Send added in v1.3.0

func (s *ResponseEmpty) Send(writer any) IErrorArgs

type Server added in v1.3.0

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

func (*Server) Addr added in v1.3.0

func (s *Server) Addr() string

func (*Server) Close added in v1.3.0

func (s *Server) Close() error

func (*Server) Context added in v1.3.0

func (s *Server) Context() context.Context

func (*Server) HandleFunc added in v1.3.0

func (s *Server) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*Server) Listen added in v1.3.0

func (s *Server) Listen(timeout time.Duration) (err error)

func (*Server) Secret added in v1.3.0

func (s *Server) Secret() []byte

func (*Server) TokenGenerate added in v1.3.0

func (s *Server) TokenGenerate(m json.Map, expire int64) (string, error)

type TemporaryFile added in v1.3.0

type TemporaryFile struct {
	*os.File
	// contains filtered or unexported fields
}

func (*TemporaryFile) Close added in v1.3.0

func (s *TemporaryFile) Close() error

func (*TemporaryFile) Len added in v1.3.0

func (s *TemporaryFile) Len() int64

type Time added in v1.3.3

type Time time.Time

Time используется для формирования объекта времени из формата UnixMilli, а так же выгрузки в этот формат в результирующем объекте

func (*Time) RestFields added in v1.3.3

func (s *Time) RestFields(fieldName string, names ...any) (any, IErrorArgs)

RestFields выгружает объект в результирующий объект в формат UnixMilli

func (*Time) RestFrom added in v1.3.3

func (s *Time) RestFrom(source any) (err IErrorArgs)

RestFrom формирует из поля типа int64 объект времени

type TokenGenerateMethod added in v1.3.0

type TokenGenerateMethod func(data json.Map, expire int64) (string, error)

type Validator

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

func NewValidator

func NewValidator(method func(r IRequestIn) IRequestOut) *Validator

func (*Validator) Validate

func (s *Validator) Validate(r IRequestIn) IRequestOut

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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