server

package
v0.0.0-...-b99927b Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorHandlerNotFound = "handler not found"
	ErrorAuthFailed      = "handler auth failed"
)
View Source
var (
	FallbackErrorMessage = "error"
)

Functions

func AuthNone

func AuthNone() func(ctx *RequestContext, token string) bool

Types

type DownloadHandler

type DownloadHandler interface {
	Match(key string) bool
	Lifetime() time.Duration
	Limit() int
	GetIsAlive() bool
	GetContentType() string
	Pull() (io.Reader, error)
	Remove() error
}

type DownloadHandlerFile

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

func NewDownloadHandlerFile

func NewDownloadHandlerFile(
	key string,
	lifetime time.Duration,
	limit int,
	contentType string,
	path string,
) *DownloadHandlerFile

func (*DownloadHandlerFile) GetContentType

func (handler *DownloadHandlerFile) GetContentType() string

func (*DownloadHandlerFile) GetIsAlive

func (handler *DownloadHandlerFile) GetIsAlive() bool

func (*DownloadHandlerFile) Lifetime

func (handler *DownloadHandlerFile) Lifetime() time.Duration

func (*DownloadHandlerFile) Limit

func (handler *DownloadHandlerFile) Limit() int

func (*DownloadHandlerFile) Match

func (handler *DownloadHandlerFile) Match(key string) bool

func (*DownloadHandlerFile) Pull

func (handler *DownloadHandlerFile) Pull() (reader io.Reader, err error)

func (*DownloadHandlerFile) Remove

func (handler *DownloadHandlerFile) Remove() (err error)

type Executor

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

func NewExecutor

func NewExecutor(queueLimit int) (executor *Executor)

func (*Executor) AddDownloadHandler

func (executor *Executor) AddDownloadHandler(handler DownloadHandler)

func (*Executor) AddHandler

func (executor *Executor) AddHandler(handler Handler)

func (*Executor) CreateQueueEntry

func (executor *Executor) CreateQueueEntry(
	clientMode client.ClientMode,
	outgoing chan generic.Pair[int, []byte],
	request proto.Request,
) generic.Pair[*RequestContext, *proto.Promise[proto.Result]]

func (*Executor) ExecuteOne

func (executor *Executor) ExecuteOne() (err error)

func (*Executor) ExecuteRequest

func (executor *Executor) ExecuteRequest(ctx *RequestContext) (result proto.Result, err error)

func (*Executor) GetDownloadHandlerAlive

func (executor *Executor) GetDownloadHandlerAlive(key string) (result optionals.Optional[DownloadHandler])

func (*Executor) GetHandler

func (executor *Executor) GetHandler(namespace string, method string) (result optionals.Optional[Handler])

func (*Executor) LoopClearHandlers

func (executor *Executor) LoopClearHandlers()

func (*Executor) LoopExecute

func (executor *Executor) LoopExecute(duration time.Duration)

func (*Executor) PushRequest

func (executor *Executor) PushRequest(clientMode client.ClientMode, outgoing chan generic.Pair[int, []byte], request proto.Request) (entry *proto.Promise[proto.Result], flag bool)

func (*Executor) Start

func (executor *Executor) Start(loop time.Duration) (err error)

type Handler

type Handler interface {
	Match(namespace string, method string) bool
	Auth(ctx *RequestContext, token string) bool
	Execute(ctx *RequestContext, request proto.Request) (result proto.Result)
}

func NewHandler

func NewHandler(
	fnMatch HandlerMatchFunction,
	fnAuth HandlerAuthFunction,
	fnExecute HandlerExecuteFunction,
) Handler

func NewHandlerWith

func NewHandlerWith(namespace string, method string, fnAuth HandlerAuthFunction, fnExecute HandlerExecuteFunction) Handler

func NewHandlerWithToken

func NewHandlerWithToken(namespace string, method string, token string, fnExecute HandlerExecuteFunction) Handler

type HandlerAuthFunction

type HandlerAuthFunction func(ctx *RequestContext, token string) bool

type HandlerBase

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

func (*HandlerBase) Auth

func (handler *HandlerBase) Auth(ctx *RequestContext, token string) bool

func (*HandlerBase) Execute

func (handler *HandlerBase) Execute(ctx *RequestContext, request proto.Request) (result proto.Result)

func (*HandlerBase) Match

func (handler *HandlerBase) Match(namespace string, method string) bool

type HandlerExecuteFunction

type HandlerExecuteFunction func(ctx *RequestContext, request proto.Request) (result proto.Result)

type HandlerMatchFunction

type HandlerMatchFunction func(namespace string, method string) bool

type RequestContext

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

func NewRequestContext

func NewRequestContext(executor *Executor, clientMode client.ClientMode, outgoing chan generic.Pair[int, []byte], request proto.Request) *RequestContext

func (*RequestContext) GetClientMode

func (ctx *RequestContext) GetClientMode() client.ClientMode

func (*RequestContext) GetConn

func (ctx *RequestContext) GetConn() optionals.Optional[chan generic.Pair[int, []byte]]

func (*RequestContext) GetExecutor

func (ctx *RequestContext) GetExecutor() *Executor

func (*RequestContext) GetRequest

func (ctx *RequestContext) GetRequest() proto.Request

type Server

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

func NewServer

func NewServer() *Server

func NewServerWithSettings

func NewServerWithSettings(settings Settings) *Server

func (*Server) AddDownloadHandler

func (server *Server) AddDownloadHandler(handler DownloadHandler)

func (*Server) AddHandler

func (server *Server) AddHandler(handler Handler)

func (*Server) Addr

func (server *Server) Addr() string

func (*Server) ErrorResult

func (server *Server) ErrorResult(err string) (result proto.Result)

func (*Server) HandleConnect

func (server *Server) HandleConnect(ctx *gin.Context)

func (*Server) HandleConnection

func (server *Server) HandleConnection(conn *websocket.Conn)

func (*Server) HandleDownload

func (server *Server) HandleDownload(ctx *gin.Context)

func (*Server) HandleExecute

func (server *Server) HandleExecute(ctx *gin.Context)

func (*Server) Run

func (server *Server) Run() (err error)

type Settings

type Settings struct {
	Port          uint16
	ExecutorLimit int
	ExecutorDelay time.Duration
}

func NewSettingsDefault

func NewSettingsDefault() Settings

Jump to

Keyboard shortcuts

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