gosrv

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: MIT Imports: 12 Imported by: 0

README

GoSRV

The awesome GoSRV library for Golang, aims to bring developer friendliness to just about every project.

Go Report Card Test Status MIT license Go.Dev reference

Getting Started

Visit GoSRV wiki page for more info

License

Released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendRequest

func SendRequest[T any](client Client, method, channel string, data any) (value T, err error)

Types

type BootHandler added in v1.0.1

type BootHandler func() (err error)

type Client

type Client interface {
	UpdateHandler(subscribers ...UpdateSubscriber)
	On(method, channel string, handler UpdateHandler)
	SendRequest(method, channel string, data any) (resp Response, err error)
	Start(errChan ...chan error)
	Stop() error
}

func NewClient

func NewClient(opts ClientOptions) Client

type ClientBootHandler

type ClientBootHandler func(client NetIO) (err error)

type ClientConn

type ClientConn interface {
	NetConn
	ClientUpdater

	ReadRequest() (req *Request, err error)
	WriteResponse(data *Response) (n int, err error)
	WriteError(data *Data) (n int, err error)
}

type ClientOptions

type ClientOptions struct {
	ServerHost  string `binding:"required"`
	ServerPort  string `binding:"required"`
	Info        *Info  `binding:"required"`
	CertOptions *cert.Options
}

type ClientReadyHandler

type ClientReadyHandler func(client ClientUpdater) (err error)

type ClientUpdater

type ClientUpdater interface {
	WriteUpdate(data Update) (n int, err error)
}

type Context

type Context interface {
	ParseContent(v any) (err error)
	Update(v any, codes ...int) (n int, err error)
	UpdateAll(v any, codes ...int)
	Output(v any, code ...int) (data Output)
	Success(v any) (data Output)
	Error(v any, code ...int) (data Output)
}

type Data

type Data interface {
	// SetContent(v any) (err error)
	ParseContent(v any) (err error)
}

type DataWithCode

type DataWithCode interface {
	Data

	GetError() (err error)
}

type Info

type Info struct {
	Name        string `json:"name"`
	Alias       string `json:"alias"`
	Description string `json:"description"`
}

type KCallback

type KCallback[K any] func(i K) string

type KCollection

type KCollection[K any, T any] interface {
	Has(i K) bool
	GetAll(i K) (values []T)
	Get(i K) (value T, ok bool)
	Add(i K, value T)
	AddOne(i K, value T) (ok bool)
}

type MCollection

type MCollection[T any] interface {
	Has(method, channel string) bool
	GetAll(method, channel string) (values []T)
	Get(method, channel string) (value T, ok bool)
	Add(method, channel string, value T)
	AddOne(method, channel string, value T) (ok bool)
}

type NetConn

type NetConn interface {
	NetIO

	ReadInfo() (*Info, error)
	WriteInfo(info *Info) (n int, err error)

	Close() error
}

type NetIO

type NetIO interface {
	NetReader
	NetWriter
}

type NetReader

type NetReader interface {
	Read(b []byte) (n int, err error)
	ReadByte() (b byte, err error)
	ReadBytes(delim byte) (b []byte, err error)
	ReadLine(delim byte) (line []byte, isPrefix bool, err error)
	ReadRune() (r rune, size int, err error)
	ReadSlice(delim byte) (line []byte, err error)
	ReadString(delim byte) (s string, err error)
}

type NetWriter

type NetWriter interface {
	Write(b []byte) (n int, err error)
	WriteLine(b []byte) (n int, err error)
	WriteString(s string) (n int, err error)
	WriteStringLine(s string) (n int, err error)
}

type Options

type Options interface {
	// contains filtered or unexported methods
}

type Output

type Output interface {
	GetCode() int
	GetContent() any
}

type ReadyHandler added in v1.0.1

type ReadyHandler func() (err error)

type Request

type Request interface {
	Data
}

type RequestHandler

type RequestHandler func(ctx Context) Output

type RequestHandlerCollection

type RequestHandlerCollection interface {
	On(method, channel string, handler RequestHandler) (err error)
}

type RequestHandlerSubscriber

type RequestHandlerSubscriber func(collection RequestHandlerCollection)

type Response

type Response interface {
	DataWithCode

	GetRequest() Request
}

type ResponseHandler

type ResponseHandler func(data *pResponse)

type Server

type Server interface {
	Listen(errChan ...chan error)
	OnBoot(handlers ...BootHandler)
	OnReady(handlers ...ReadyHandler)
	OnClientBoot(handlers ...ClientBootHandler)
	OnClientReady(handlers ...ClientReadyHandler)
	RequestHandlers(subscribers ...RequestHandlerSubscriber)
	Stop() error
}

func NewServer

func NewServer(opts ServerOptions) Server

type ServerConn

type ServerConn interface {
	NetConn
}

type ServerOptions

type ServerOptions struct {
	Host        string `binding:"required"`
	Port        string `binding:"required"`
	Info        *Info  `binding:"required"`
	CertOptions *cert.Options
}

type Update

type Update interface {
	DataWithCode
}

type UpdateHandler

type UpdateHandler func(data Update)

type UpdateSubscriber

type UpdateSubscriber func(collection MCollection[UpdateHandler])

Jump to

Keyboard shortcuts

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