Documentation ¶
Index ¶
- Constants
- Variables
- func Register(zeroValues ...type32.TypeIDer32)
- type Client
- type ClientEndpoints
- type Conn
- type Mux
- type Request
- func (r *Request) ErrCheck(err error) *Response
- func (r *Request) Redirect(url string) *Response
- func (r *Request) Response(body []byte) *Response
- func (r *Request) ResponseErr(err error, status int) *Response
- func (r *Request) ResponseString(body string) *Response
- func (r *Request) ResponseTemplate(name string, t luceio.TemplateExecutor, data any) *Response
- func (r *Request) SerializeResponse(s serial.Serializer, data any, buf []byte) (*Response, error)
- func (r *Request) ServeFile(path string) (resp *Response)
- func (*Request) TypeID32() uint32
- type RequestHandler
- type RequestResponder
- type Require
- type Response
- func (r *Response) ContentType(val string) *Response
- func (r *Response) ErrCheck(err error) (notNil bool)
- func (r *Response) SetHeader(key, val string) *Response
- func (r *Response) SetStatus(status int) *Response
- func (*Response) TypeID32() uint32
- func (r *Response) Write(p []byte) (n int, err error)
- type RouteConfig
- func (r *RouteConfig) AddMethod(method string) *RouteConfig
- func (r *RouteConfig) Delete() *RouteConfig
- func (r *RouteConfig) Get() *RouteConfig
- func (r *RouteConfig) Methods() []string
- func (r *RouteConfig) Post() *RouteConfig
- func (r *RouteConfig) Put() *RouteConfig
- func (r *RouteConfig) RequireGroup(group string) *RouteConfig
- func (r *RouteConfig) SetHost(host string) *RouteConfig
- func (r *RouteConfig) String() string
- func (r *RouteConfig) Validate() error
- func (r *RouteConfig) WithBody() *RouteConfig
- func (r *RouteConfig) WithForm() *RouteConfig
- func (r *RouteConfig) WithPrefix() *RouteConfig
- func (r *RouteConfig) WithQuery() *RouteConfig
- func (r *RouteConfig) WithUser() *RouteConfig
- type RouteConfigGen
- func (r *RouteConfigGen) Copy() *RouteConfigGen
- func (g *RouteConfigGen) Get(path string) *RouteConfig
- func (g *RouteConfigGen) GetQuery(path string) *RouteConfig
- func (g *RouteConfigGen) Path(path string) *RouteConfig
- func (g *RouteConfigGen) Post(path string) *RouteConfig
- func (g *RouteConfigGen) PostForm(path string) *RouteConfig
- func (r *RouteConfigGen) RequireGroup(group string) *RouteConfigGen
- func (r *RouteConfigGen) SetHost(host string) *RouteConfigGen
- func (g *RouteConfigGen) WithUser() *RouteConfigGen
- type Routes
- type SocketClose
- type SocketMessage
- type SocketOpened
Constants ¶
const ContentType = "Content-Type"
const ErrPathRequired = lerr.Str("RouteConfig: Path is required")
const HttpRedirect = 302
Variables ¶
var OS lfile.FSFileReader = lfile.OSRepository{}
var RequestResponderFilter = filter.ConvertableTo[RequestResponder]()
Functions ¶
func Register ¶
func Register(zeroValues ...type32.TypeIDer32)
Register types with both gob and the typemap.
Types ¶
type Client ¶
func (*Client) Add ¶
func (c *Client) Add(h RequestResponder, r *RouteConfig)
type ClientEndpoints ¶
type ClientEndpoints struct { *Client Endpoints lmap.Wrapper[string, RequestResponder] Counters lmap.Wrapper[string, int] }
func NewClientEndpoints ¶
func NewClientEndpoints(addr string, endpoints any) (ce ClientEndpoints, err error)
NewClientEndpoints solves a specific problem. Creating an endpoint function but forgetting to register it with the Client. ClientEndpoints finds all methods on the endpoints object that fulfill RequestResponder. As each is used to add a route to the Client it is removed the Endpoints map. Calling UnusedEnpoints will panic if a RequestResponder was added but not used in a route.
func (ClientEndpoints) Add ¶
func (ce ClientEndpoints) Add(handler string, rCfg *RouteConfig)
Add pops the endpoints associated with the handler and adds it to the client with the given route. Ths allows UnusedEnpoints to be called which will panic if any handlers are unused.
func (ClientEndpoints) UnusedEnpoints ¶
func (ce ClientEndpoints) UnusedEnpoints()
UnusedEnpoints panics if any endpoints are unused
type Mux ¶
type Mux struct { Handlers map[string]RequestHandler Routes Routes }
Mux maps the Requests to their handlers.
func (*Mux) Add ¶
func (m *Mux) Add(h RequestHandler, r *RouteConfig)
Add a RequestHandler to the Mux mapped to the RouteConfig.
type Request ¶
type Request struct { ID uint32 RouteConfig string Path string Method string PathVars map[string]string Query map[string]string Form url.Values Body []byte User *lusers.User }
Request represents a user request that the luce Server is relaying to the service.
func (*Request) ResponseErr ¶
ResponseErr sets the response body to the error and sets the status.
func (*Request) ResponseString ¶
ResponseString to the Request.
func (*Request) ResponseTemplate ¶
ResponseTemplate populates the body of the response using the provided template and data. If there is a template error, that will populate the body.
func (*Request) SerializeResponse ¶
SerializeResponse uses the provided Serializer and data to create a Response to the Request.
type RequestHandler ¶
type RequestHandler func(r *Request)
RequestHandler will handle a request but it will not respond to it.
type RequestResponder ¶
RequestResponder will hand a request and return a reponse.
type Require ¶
type Require struct {
Group string
}
Require breaks out the possible route requirements so the logic can be shared between RouteConfigGen and RouteConfig.
func (*Require) RequireGroup ¶
RequireGroup sets or appends the group to the Group field.
type Response ¶
Response to a request. The ID is the same as the ID is taken from the request.
func (*Response) ContentType ¶
func (*Response) ErrCheck ¶
ErrCheck will set the response to the error body only if err is not nil. In this case it will check if the error fulfills lhttp.StatusErr and use that for the status, other wise it will set the status to StatusInternalServerError.
type RouteConfig ¶
type RouteConfig struct { ID string Path string Host string // Method is comma delimited methods that are accepted Method string PathPrefix bool PathVars bool Form bool Body bool User bool Query bool Require }
func NewRoute ¶
func NewRoute(path string) *RouteConfig
NewRoute defi* Routesned by path (relative to the base path).
func (*RouteConfig) AddMethod ¶
func (r *RouteConfig) AddMethod(method string) *RouteConfig
AddMethod is a chainable helper. It sets the Method field. If the Method field is not empty, it appends the input with comma seperation.
func (*RouteConfig) Delete ¶
func (r *RouteConfig) Delete() *RouteConfig
Delete is a chainable helper. It adds Delete to the Method field.
func (*RouteConfig) Get ¶
func (r *RouteConfig) Get() *RouteConfig
Get is a chainable helper. It adds Get to the Method field.
func (*RouteConfig) Methods ¶
func (r *RouteConfig) Methods() []string
func (*RouteConfig) Post ¶
func (r *RouteConfig) Post() *RouteConfig
Post is a chainable helper. It adds Post to the Method field.
func (*RouteConfig) Put ¶
func (r *RouteConfig) Put() *RouteConfig
Put is a chainable helper. It adds Put to the Method field.
func (*RouteConfig) RequireGroup ¶
func (r *RouteConfig) RequireGroup(group string) *RouteConfig
RequireGroup is a chainable helper. It calls RequireGroup on the embedded Require.
func (*RouteConfig) SetHost ¶
func (r *RouteConfig) SetHost(host string) *RouteConfig
SetHost is a chainable helper. It sets the Host field.
func (*RouteConfig) String ¶
func (r *RouteConfig) String() string
String fulfills Stringer. Returns the RouteConfig as "(Method)path...", where the ellipse will only be present if the path is a prefix.
func (*RouteConfig) Validate ¶
func (r *RouteConfig) Validate() error
Validate the RouteConfig has necessary fields filled in. Unset fields will be set to their defaults.
func (*RouteConfig) WithBody ¶
func (r *RouteConfig) WithBody() *RouteConfig
WithBody is a chainable helper. It sets the Body field to true.
func (*RouteConfig) WithForm ¶
func (r *RouteConfig) WithForm() *RouteConfig
WithQuery is a chainable helper. It sets the Form field to true.
func (*RouteConfig) WithPrefix ¶
func (r *RouteConfig) WithPrefix() *RouteConfig
WithPrefix is a chainable helper. It sets the PathPrefix field to true.
func (*RouteConfig) WithQuery ¶
func (r *RouteConfig) WithQuery() *RouteConfig
WithQuery is a chainable helper. It sets the Query field to true.
func (*RouteConfig) WithUser ¶
func (r *RouteConfig) WithUser() *RouteConfig
WithUser is a chainable helper. It sets the User field to true.
type RouteConfigGen ¶
RouteConfigGen is used to create RouteConfigs from a Base path.
func NewRouteConfigGen ¶
func NewRouteConfigGen(basePath string) *RouteConfigGen
func (*RouteConfigGen) Copy ¶
func (r *RouteConfigGen) Copy() *RouteConfigGen
func (*RouteConfigGen) Get ¶
func (g *RouteConfigGen) Get(path string) *RouteConfig
Get creates a RouteConfig with a Path of Base+path at
func (*RouteConfigGen) GetQuery ¶
func (g *RouteConfigGen) GetQuery(path string) *RouteConfig
GetQuery creates a clone of the RouteConfigGen appending path to the Base and setting the method to Get.
func (*RouteConfigGen) Path ¶
func (g *RouteConfigGen) Path(path string) *RouteConfig
Path creates a RouteConfig appending path to the Base and copying the Require object.
func (*RouteConfigGen) Post ¶
func (g *RouteConfigGen) Post(path string) *RouteConfig
GetQuery creates a clone of the RouteConfigGen appending path to the Base and setting the method to Post.
func (*RouteConfigGen) PostForm ¶
func (g *RouteConfigGen) PostForm(path string) *RouteConfig
GetQuery creates a clone of the RouteConfigGen appending path to the Base and setting the method to Post and enabling form data to be included in the requets.
func (*RouteConfigGen) RequireGroup ¶
func (r *RouteConfigGen) RequireGroup(group string) *RouteConfigGen
RequireGroup is a chainable helper. It calls RequireGroup on the embedded Require.
func (*RouteConfigGen) SetHost ¶
func (r *RouteConfigGen) SetHost(host string) *RouteConfigGen
SetHost is a chainable helper. It sets the Host field.
func (*RouteConfigGen) WithUser ¶
func (g *RouteConfigGen) WithUser() *RouteConfigGen
type SocketClose ¶
type SocketClose struct {
ID uint32
}
func (SocketClose) TypeID32 ¶
func (SocketClose) TypeID32() uint32
TypeID32 fulfill TypeIDer32. The ID was choosen at random.
type SocketMessage ¶
func (SocketMessage) TypeID32 ¶
func (SocketMessage) TypeID32() uint32
TypeID32 fulfill TypeIDer32. The ID was choosen at random.
type SocketOpened ¶
type SocketOpened struct {
ID uint32
}
func (SocketOpened) TypeID32 ¶
func (SocketOpened) TypeID32() uint32
TypeID32 fulfill TypeIDer32. The ID was choosen at random.