package types
import "go.trulyao.dev/robin/types"
Index ¶
- type CastError
- type Context
- func NewContext(req *http.Request, res *http.ResponseWriter) *Context
- func (c *Context) Cookie(key string) (*http.Cookie, bool)
- func (c *Context) DisableStateMutex()
- func (c *Context) EnableStateMutex()
- func (c *Context) Get(key string) any
- func (c *Context) GetBody() []byte
- func (c *Context) Header(key string) string
- func (c *Context) ProcedureName() string
- func (c *Context) ProcedureType() ProcedureType
- func (c *Context) Query(key string) string
- func (c *Context) Request() *http.Request
- func (c *Context) Response() http.ResponseWriter
- func (c *Context) Set(key string, value any)
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetProcedureName(name string)
- func (c *Context) SetProcedureType(procedureType ProcedureType)
- type Error
- func NewError(message string, code ...int) *Error
- func (e Error) Error() string
- func (e *Error) WithCause(cause error) *Error
- func (e *Error) WithCode(code int) *Error
- func (e *Error) WithMeta(meta map[string]interface{}) *Error
- type ExclusionList
- func (e *ExclusionList) Add(name string)
- func (e *ExclusionList) AddMany(names []string)
- func (e *ExclusionList) Clear()
- func (e *ExclusionList) Has(name string) bool
- type HttpMethod
- type JSONSerializable
- type Middleware
- type Procedure
- type ProcedureType
- type RobinError
- type State
- func NewState() State
- func (s *State) Get(key string) any
- func (s *State) Set(key string, value any)
- func (s *State) UseMutex(useMutex bool)
- type Void
Types ¶
type CastError ¶
func (CastError) Error ¶
type Context ¶
type Context struct { // User-defined state - this can be used to store any data that needs to be shared across procedures // For example, database connections, etc. // // NOTE: this is shared across all a functions in a single request State State // contains filtered or unexported fields }
func NewContext ¶
func NewContext(req *http.Request, res *http.ResponseWriter) *Context
func (*Context) Cookie ¶
Cookie returns the cookie with the specified key from the request and a boolean indicating whether the cookie exists
func (*Context) DisableStateMutex ¶
func (c *Context) DisableStateMutex()
DisableStateMutex disables the mutex lock on the state container
func (*Context) EnableStateMutex ¶
func (c *Context) EnableStateMutex()
EnableStateMutex enables the mutex lock on the state container
func (*Context) Get ¶
Get gets a value from the state container
func (*Context) GetBody ¶
GetBody returns the body of the request as a byte slice
func (*Context) Header ¶
Header returns the value of the specified header
func (*Context) ProcedureName ¶
ProcedureName returns the name of the procedure
func (*Context) ProcedureType ¶
func (c *Context) ProcedureType() ProcedureType
ProcedureType returns the type of the procedure
func (*Context) Query ¶
Query returns the value of the specified query parameter
func (*Context) Request ¶
Request returns the underlying request
func (*Context) Response ¶
func (c *Context) Response() http.ResponseWriter
Response returns the underlying response writer
func (*Context) Set ¶
Set sets a value in the state container
func (*Context) SetCookie ¶
SetCookie sets a cookie in the response
func (*Context) SetHeader ¶
SetHeader sets the value of the specified header
func (*Context) SetProcedureName ¶
SetProcedureName sets the name of the procedure
func (*Context) SetProcedureType ¶
func (c *Context) SetProcedureType(procedureType ProcedureType)
SetProcedureType sets the type of the procedure
type Error ¶
func NewError ¶
func (Error) Error ¶
func (*Error) WithCause ¶
func (*Error) WithCode ¶
func (*Error) WithMeta ¶
type ExclusionList ¶
type ExclusionList []string
func (*ExclusionList) Add ¶
func (e *ExclusionList) Add(name string)
Add adds a name to the exclusion list
func (*ExclusionList) AddMany ¶
func (e *ExclusionList) AddMany(names []string)
AddMany adds multiple names to the exclusion list
func (*ExclusionList) Clear ¶
func (e *ExclusionList) Clear()
Clear clears the exclusion list to free up memory
func (*ExclusionList) Has ¶
func (e *ExclusionList) Has(name string) bool
Contains checks if a name is in the exclusion list
type HttpMethod ¶
type HttpMethod string
const ( HttpMethodGet HttpMethod = "GET" HttpMethodPost HttpMethod = "POST" HttpMethodPut HttpMethod = "PUT" HttpMethodPatch HttpMethod = "PATCH" HttpMethodDelete HttpMethod = "DELETE" )
type JSONSerializable ¶
type JSONSerializable interface { json.Marshaler json.Unmarshaler }
type Middleware ¶
type Procedure ¶
type Procedure interface { // The name of the procedure Name() string // The type of the procedure, one of 'query' or 'mutation' Type() ProcedureType // Return an empty type that represents the payload that the procedure expects // WARNING: whatever is returned here is only used for type inference/reflection during runtime; no value should be expected here PayloadInterface() any // Return an empty type that represents the return value of the procedure // WARNING: whatever is returned here is only used for type inference/reflection during runtime; no value should be expected here ReturnInterface() any // Check if the procedure expects a payload or not // This is useful for procedures that don't expect a payload, so we can instantly skip the payload decoding step ExpectsPayload() bool // Call the procedure with the given context and payload Call(*Context, any) (any, error) // Validate the procedure Validate() error // Middleware to be executed before the procedure is called MiddlewareFns() []Middleware // Set the middleware functions for the procedure at the beginning of the middleware chain // You ideally should not use this method, use WithMiddleware instead unless you absolutely need to prepend middleware functions to the chain PrependMiddleware(...Middleware) Procedure // Set the middleware functions for the procedure WithMiddleware(...Middleware) Procedure ExcludedMiddleware() *ExclusionList // Exclude middleware functions from the procedure ExcludeMiddleware(...string) Procedure // Alias the procedure with a different name for the REST API (and other potential future use cases) WithAlias(string) Procedure // Get the alias of the Procedure if it has one, otherwise, it returns a normalized version of the procedure name (e.g. `get_user` -> `user`, `todo.create` -> `todo.create`, `find-users` -> `users`) // // Common words like `get`, `find`, `create`, `update`, `delete` are normalized to their respective actions based on the procedure type Alias() string }
type ProcedureType ¶
type ProcedureType string
const ( ProcedureTypeQuery ProcedureType = "query" ProcedureTypeMutation ProcedureType = "mutation" )
type RobinError ¶
func (RobinError) Error ¶
func (ie RobinError) Error() string
type State ¶
type State struct {
// contains filtered or unexported fields
}
A container for user-defined state
func NewState ¶
func NewState() State
func (*State) Get ¶
Get gets a value from the state container
func (*State) Set ¶
Set sets a value in the state container
func (*State) UseMutex ¶
UseMutex sets whether to use the mutex lock on the state container
type Void ¶
type Void = _RobinVoid
No-op type to represent a procedure that doesn't return any response or take any payload
Source Files ¶
context.go error.go middleware.go procedure.go
- Version
- v0.7.0 (latest)
- Published
- Mar 7, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 1 hour ago –
Tools for package owners.