nexus

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 14 Imported by: 1

README

License

Nexus

a little Server Framework for Go allows you to create Object Oriented Server Endpoints.

Support

If you find this project useful, you can support its development by buying me a coffee:

Buy Me A Coffee

Documentation

Index

Constants

View Source
const ExecuteNoMiddleware = "###NoMiddleware###"
View Source
const TraceIDKey contextKey = "trace_id"

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEndpoint

type BaseEndpoint struct {
	RequestUtils  RequestUtils
	ResponseUtils ResponseUtils
	// contains filtered or unexported fields
}

func NewBaseEndpoint

func NewBaseEndpoint() *BaseEndpoint

func (*BaseEndpoint) After

func (endpoint *BaseEndpoint) After(http.ResponseWriter, *http.Request) *HttpError

func (*BaseEndpoint) Before

func (endpoint *BaseEndpoint) Before(http.ResponseWriter, *http.Request) *HttpError

func (*BaseEndpoint) ExplicitMiddlewares

func (endpoint *BaseEndpoint) ExplicitMiddlewares() []string

func (*BaseEndpoint) GetRoute

func (endpoint *BaseEndpoint) GetRoute() string

func (*BaseEndpoint) Handler

func (endpoint *BaseEndpoint) Handler(http.ResponseWriter, *http.Request) *HttpError

func (*BaseEndpoint) Methods

func (endpoint *BaseEndpoint) Methods() []string

func (*BaseEndpoint) OnError

func (endpoint *BaseEndpoint) OnError(err *HttpError, w http.ResponseWriter, r *http.Request)

type BaseWebsocket

type BaseWebsocket struct {
	Pool ClientPool
}

func NewBaseWebsocket

func NewBaseWebsocket() *BaseWebsocket

func (*BaseWebsocket) CheckOrigin

func (socket *BaseWebsocket) CheckOrigin(r *http.Request) bool

func (*BaseWebsocket) ClientConnect

func (socket *BaseWebsocket) ClientConnect(client WebsocketClient) fail.CustomError

func (*BaseWebsocket) EnableCompression

func (socket *BaseWebsocket) EnableCompression() bool

func (*BaseWebsocket) GetRoute

func (socket *BaseWebsocket) GetRoute() string

func (*BaseWebsocket) Handle

func (socket *BaseWebsocket) Handle(data []byte, client WebsocketClient) fail.CustomError

func (*BaseWebsocket) Handshake

func (socket *BaseWebsocket) Handshake(w http.ResponseWriter, r *http.Request) *HttpError

func (*BaseWebsocket) ReadBufferSize

func (socket *BaseWebsocket) ReadBufferSize() int

func (*BaseWebsocket) WriteBufferSize

func (socket *BaseWebsocket) WriteBufferSize() int

type ClientPool

type ClientPool interface {
	Register(client WebsocketClient)
	Get(filter func(client WebsocketClient) bool) []WebsocketClient
}

type Config

type Config struct {
	ListenAddress       string
	Middlewares         []Middleware
	Endpoints           map[string][]Endpoint
	StaticFiles         http.FileSystem
	CrossOriginRequests CorsConfig
	Websockets          []Websocket
}

type CorsConfig

type CorsConfig struct {
	AllowedOrigins   []string
	AllowedMethods   []string
	AllowedHeaders   []string
	AllowCredentials bool
}

type Endpoint

type Endpoint interface {
	Methods() []string
	GetRoute() string
	ExplicitMiddlewares() []string
	Handler(http.ResponseWriter, *http.Request) *HttpError
	Before(http.ResponseWriter, *http.Request) *HttpError
	After(http.ResponseWriter, *http.Request) *HttpError
	OnError(err *HttpError, w http.ResponseWriter, r *http.Request)
}

type HttpError

type HttpError struct {
	Status int
	Error  error
}

func NewHttpError

func NewHttpError(err fail.CustomError, status int) *HttpError

type Middleware

type Middleware interface {
	GetKey() string
	Execute(w http.ResponseWriter, r *http.Request) *HttpError
}

type RequestUtils

type RequestUtils interface {
	GetBearerToken(r *http.Request) string
	GetClientIP(r *http.Request) string
	GetPreferredLanguage(r *http.Request, supportedLanguages []string) string
	GetTraceID(r *http.Request) string
	GetHeaderValue(r *http.Request, name string) string
	GetUrlParam(r *http.Request, name string) string
	GetUrlParamInt(r *http.Request, name string, defaultValue int) int
	GetUrlParamBool(r *http.Request, name string, defaultValue bool) bool
	GetUrlParamFloat32(r *http.Request, name string, defaultValue float32) float32
	GetUrlParamFloat64(r *http.Request, name string, defaultValue float64) float64
	GetFormData(r *http.Request, name string) (string, fail.CustomError)
	GetRawBody(r *http.Request) ([]byte, fail.CustomError)
	GetJsonBody(r *http.Request, target any) fail.CustomError
}

type ResponseUtils

type ResponseUtils interface {
	WritePlainText(status int, data string, w http.ResponseWriter) *HttpError
	WriteBytes(status int, data []byte, w http.ResponseWriter) *HttpError
	WriteJson(status int, data any, w http.ResponseWriter) *HttpError
	WriteEmpty(status int, w http.ResponseWriter) *HttpError
	WriteError(err *HttpError, w http.ResponseWriter)
}

type Runner

type Runner interface {
	Start(config Config) fail.CustomError
}

func New

func New(instance Runner) Runner

type Websocket

type Websocket interface {
	GetRoute() string
	Handshake(w http.ResponseWriter, r *http.Request) *HttpError
	ClientConnect(client WebsocketClient) fail.CustomError
	CheckOrigin(r *http.Request) bool
	ReadBufferSize() int
	WriteBufferSize() int
	EnableCompression() bool
	Handle(data []byte, client WebsocketClient) fail.CustomError
}

type WebsocketClient

type WebsocketClient interface {
	GetId() string
	Send(data []byte) fail.CustomError
	SendJson(data any) fail.CustomError
	Close() fail.CustomError
	Closed() *fail.ErrorList
	OnClose(toDo func() fail.CustomError)
}

Jump to

Keyboard shortcuts

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