rest

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyOpened  = "AlreadyOpened"
	ErrNotOpened      = "NotOpened"
	ErrKeyNotExists   = "KeyNotExists"
	ErrKeyInvalidType = "KeyInvalidType"
	ErrNotFound       = "NotFound"
)

Functions

This section is empty.

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 *Request) *Response

func (*Command) Validate

func (s *Command) Validate(r *Request) *Response

type CommandStore

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

func NewCommandStore

func NewCommandStore() *CommandStore

func (*CommandStore) AddCommand

func (s *CommandStore) AddCommand(uri string, command ICommand)

func (*CommandStore) AddCommandMethods

func (s *CommandStore) AddCommandMethods(uri string, validate func(*Request) *Response, execute func(*Request) *Response)

func (*CommandStore) AddCommandObjects

func (s *CommandStore) AddCommandObjects(uri string, validator IValidator, executor IExecuter)

func (*CommandStore) GetCommand

func (s *CommandStore) GetCommand(uri string) (ICommand, bool)

type Error

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

func (*Error) Error

func (s *Error) Error() string

func (*Error) Map

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

type Executer

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

func NewExecuter

func NewExecuter(method func(r *Request) *Response) *Executer

func (*Executer) Execute

func (s *Executer) Execute(r *Request) *Response

type Fielder

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

func NewFielder

func NewFielder(source any) *Fielder

func (*Fielder) Fields

func (s *Fielder) Fields(names ...any) (json.Map, error)

type IApp

type IApp interface {
	Executer(r *Request) (IExecuter, bool)
}

type ICommand

type ICommand interface {
	IValidator
	IExecuter
}

type IErrorArgs

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

func NewErrFieldRequired

func NewErrFieldRequired(field string) IErrorArgs

func NewErrFieldType

func NewErrFieldType(field, fType, gType, message string) IErrorArgs

func NewErrPrtexpected

func NewErrPrtexpected(field string) IErrorArgs

func NewError

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

func NewErrorMessage

func NewErrorMessage(name, text string) IErrorArgs

type IExecuter

type IExecuter interface {
	Execute(r *Request) *Response
}

type IFieldChecker

type IFieldChecker interface {
	FieldCheck(string) bool
}

type IFielder

type IFielder interface {
	Fields(...any) (json.Map, error)
}

type IValidator

type IValidator interface {
	Validate(r *Request) *Response
}

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Request реализует объект запроса

func (*Request) Auth

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

Auth returns auth data

func (*Request) Close

func (s *Request) Close()

func (*Request) Data

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

func (*Request) File

func (s *Request) File(name string) (io.Reader, bool)

func (*Request) FileKeys

func (s *Request) FileKeys() []string

file keys

func (*Request) GenerateToken

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

func (*Request) IsAuth

func (s *Request) IsAuth() bool

func (*Request) IsForm

func (s *Request) IsForm() bool

func (*Request) IsJSON

func (s *Request) IsJSON() bool

func (*Request) RPath

func (s *Request) RPath() string

type Response

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

func NewResponse

func NewResponse() *Response

func ResponseErrKeyInvalidType

func ResponseErrKeyInvalidType(key, kType string) *Response

func ResponseErrKeyNotExists

func ResponseErrKeyNotExists(key string) *Response

func ResponseError

func ResponseError(err string, args mjson.Map, code int) *Response

func ResponseErrorMessage

func ResponseErrorMessage(err, message string, code int) *Response

func ResponseNotFound

func ResponseNotFound(data mjson.Map) *Response

func (*Response) Close

func (s *Response) Close()

func (*Response) FileSet

func (s *Response) FileSet(name string, file io.ReadCloser)

func (*Response) KeySet

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

func (*Response) Send

func (s *Response) Send(w http.ResponseWriter) error

func (*Response) SetError

func (s *Response) SetError(code int, err error)

type Rest

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

func New

func New(addr string, secret []byte, app IApp) *Rest

func (*Rest) Close

func (s *Rest) Close() error

Close

func (*Rest) Listen

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

Listen start server in other goroutine

func (*Rest) TokenGenerate

func (s *Rest) TokenGenerate(m mjson.Map, expire int64) (string, error)

type Validator

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

func NewValidator

func NewValidator(method func(r *Request) *Response) *Validator

func (*Validator) Validate

func (s *Validator) Validate(r *Request) *Response

Jump to

Keyboard shortcuts

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