restfulresolver

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const HeaderRequestID = "X-Request-Id"

Variables

This section is empty.

Functions

func CreateMiddlewareRequestLog

func CreateMiddlewareRequestLog(statics []*fs.StaticFs) func(c *Context) error

func GetHandlerInfo

func GetHandlerInfo(handler Handler, logger logger.Logger, resources ...*fs.Resource) (string, []fiber.Handler)

func MiddlewareCookie

func MiddlewareCookie(c *Context) error

func MiddlewareCors

func MiddlewareCors(c *Context) error

func MiddlewareRecover

func MiddlewareRecover(c *Context) error

func MiddlewareRequestID

func MiddlewareRequestID(c *Context) error

func RegisterResourceRoutes added in v0.3.0

func RegisterResourceRoutes(
	resources []*fs.Resource,
	router *Router,
	getHooks func() *fs.Hooks,
)

func TransformHandlers

func TransformHandlers(
	r *fs.Resource,
	handlers []Handler,
	l logger.Logger,
) []fiber.Handler

func WSResourceHandler added in v0.3.0

func WSResourceHandler(r *fs.Resource, hooks *fs.Hooks, router *Router)

Types

type BaseContext added in v0.3.0

type BaseContext = Context

type Config

type Config struct {
	AppName     string
	JSONEncoder utils.JSONMarshal
	Logger      logger.Logger
}

type Context

type Context struct {
	*fiber.Ctx
	*fasthttp.RequestCtx
	// contains filtered or unexported fields
}

func CreateContext

func CreateContext(r *fs.Resource, c *fiber.Ctx, logger logger.Logger, wsClients ...fs.WSClient) *Context

func (*Context) Arg

func (c *Context) Arg(name string, defaults ...string) string

func (*Context) ArgInt

func (c *Context) ArgInt(name string, defaults ...int) int

func (*Context) Args

func (c *Context) Args() map[string]string

func (*Context) AuthToken

func (c *Context) AuthToken() string

func (*Context) Base

func (c *Context) Base() string

func (*Context) Bind added in v0.5.0

func (c *Context) Bind(v any) error

func (*Context) Cookie

func (c *Context) Cookie(name string, values ...*Cookie) string

func (*Context) Files

func (c *Context) Files() ([]*fs.File, error)

func (*Context) Header

func (c *Context) Header(key string, vals ...string) string

func (*Context) Hostname

func (c *Context) Hostname() string

func (*Context) JSON

func (c *Context) JSON(v any) error

func (*Context) Local added in v0.5.0

func (c *Context) Local(key string, value ...any) (val any)

func (*Context) Logger

func (c *Context) Logger() logger.Logger

func (*Context) Method

func (c *Context) Method() string

func (*Context) Next

func (c *Context) Next() error

func (*Context) OriginalURL

func (c *Context) OriginalURL() string

func (*Context) Path

func (c *Context) Path() string

func (*Context) Payload added in v0.5.0

func (c *Context) Payload() (*schema.Entity, error)

func (*Context) Redirect

func (c *Context) Redirect(path string) error

func (*Context) Resource

func (c *Context) Resource() *fs.Resource

func (*Context) Response

func (c *Context) Response() *Response

func (*Context) Result

func (c *Context) Result(results ...*fs.Result) *fs.Result

func (*Context) RouteName

func (c *Context) RouteName() string

func (*Context) Send

func (c *Context) Send(data []byte) error

func (*Context) Status

func (c *Context) Status(v int) *Context

func (*Context) TraceID added in v0.5.0

func (c *Context) TraceID() string

func (*Context) User

func (c *Context) User() *fs.User

func (*Context) WSClient added in v0.3.0

func (c *Context) WSClient() fs.WSClient
type Cookie struct {
	Name        string    `json:"name"`
	Value       string    `json:"value"`
	Path        string    `json:"path"`
	Domain      string    `json:"domain"`
	MaxAge      int       `json:"max_age"`
	Expires     time.Time `json:"expires"`
	Secure      bool      `json:"secure"`
	HTTPOnly    bool      `json:"http_only"`
	SameSite    string    `json:"same_site"`
	SessionOnly bool      `json:"session_only"`
}

type Handler

type Handler func(c *Context) error

func TransformMiddlewares added in v0.3.0

func TransformMiddlewares(inputs []fs.Middleware) []Handler

type MethodData

type MethodData struct {
	Path    string
	Handler func(path string, handler Handler, resources ...*fs.Resource)
}

func CreateHTTPHandlers added in v0.3.0

func CreateHTTPHandlers(router *Router, meta *fs.Meta) []MethodData

type ResolverConfig added in v0.3.0

type ResolverConfig struct {
	ResourceManager *fs.ResourcesManager
	Logger          logger.Logger
	StaticFSs       []*fs.StaticFs
}

type Response

type Response struct {
	*fasthttp.Response
}

func (*Response) Header

func (r *Response) Header(key string, vals ...string) string

type RestfulResolver

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

func NewRestfulResolver

func NewRestfulResolver(config *ResolverConfig) *RestfulResolver

func (*RestfulResolver) Server

func (r *RestfulResolver) Server() *Server

func (*RestfulResolver) Shutdown

func (r *RestfulResolver) Shutdown() error

func (*RestfulResolver) Start

func (r *RestfulResolver) Start(address string) error

type Router

type Router struct {
	*fiber.App
	// contains filtered or unexported fields
}

func (*Router) Connect

func (g *Router) Connect(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Delete

func (g *Router) Delete(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Get

func (g *Router) Get(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Group

func (g *Router) Group(prefix string, r *fs.Resource, handlers ...Handler) *Router

func (*Router) Head

func (g *Router) Head(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Options

func (g *Router) Options(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Patch

func (g *Router) Patch(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Post

func (g *Router) Post(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Put

func (g *Router) Put(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Trace

func (g *Router) Trace(path string, handler Handler, resources ...*fs.Resource)

func (*Router) Use

func (g *Router) Use(handlers ...Handler)

type Server

type Server struct {
	*fiber.App
	// contains filtered or unexported fields
}

func New

func New(config Config) *Server

func (*Server) Connect

func (s *Server) Connect(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Delete

func (s *Server) Delete(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Get

func (s *Server) Get(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Group

func (s *Server) Group(prefix string, r *fs.Resource, handlers ...Handler) *Router

func (*Server) Head

func (s *Server) Head(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Listen

func (s *Server) Listen(address string) error

func (*Server) Options

func (s *Server) Options(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Patch

func (s *Server) Patch(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Post

func (s *Server) Post(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Put

func (s *Server) Put(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Static

func (s *Server) Static(prefix, root string, configs ...StaticConfig)

func (*Server) Test

func (s *Server) Test(req *http.Request, msTimeout ...int) (resp *http.Response, err error)

func (*Server) Trace

func (s *Server) Trace(path string, handler Handler, resources ...*fs.Resource)

func (*Server) Use

func (s *Server) Use(handlers ...Handler)

type StaticConfig

type StaticConfig struct {
	Compress      bool          `json:"compress"`
	ByteRange     bool          `json:"byte_range"`
	Browse        bool          `json:"browse"`
	Download      bool          `json:"download"`
	Index         string        `json:"index"`
	CacheDuration time.Duration `json:"cache_duration"` // Default value 10 * time.Second.
	MaxAge        int           `json:"max_age"`        // Default value 0
}

type WSClient added in v0.3.0

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

func NewWSClient added in v0.3.0

func NewWSClient(conn *websocket.Conn) *WSClient

func (*WSClient) Close added in v0.3.0

func (c *WSClient) Close(msgs ...string) error

Close closes the connection without any error

func (*WSClient) CloseWithCode added in v0.3.0

func (c *WSClient) CloseWithCode(code fs.WSCloseType, msg string) error

CloseWithCode closes the connection with the given code and message

func (*WSClient) ID added in v0.3.0

func (c *WSClient) ID() string

ID returns the ID of the connection

func (*WSClient) IsCloseNormal added in v0.3.0

func (c *WSClient) IsCloseNormal(err error) bool

IsCloseNormal checks if the close error is a normal closure

func (*WSClient) Read added in v0.3.0

func (c *WSClient) Read() (messageType fs.WSMessageType, p []byte, err error)

Read reads the next message from the WebSocket connection.

func (*WSClient) Write added in v0.3.0

func (c *WSClient) Write(data []byte, messageTypes ...fs.WSMessageType) error

Write writes the given data to the WebSocket connection. If no message types are provided, it defaults to TextMessage.

type WSContext added in v0.3.0

type WSContext struct {
	*BaseContext
	// contains filtered or unexported fields
}

func CreateWSContext added in v0.3.0

func CreateWSContext(r *fs.Resource, c *fiber.Ctx, logger logger.Logger, wsClient *WSClient) *WSContext

func (*WSContext) Arg added in v0.3.0

func (c *WSContext) Arg(name string, defaults ...string) string

func (*WSContext) ArgInt added in v0.3.0

func (c *WSContext) ArgInt(name string, defaults ...int) int

func (*WSContext) Local added in v0.5.0

func (c *WSContext) Local(key string, value ...any) (val any)

func (*WSContext) Locals added in v0.3.0

func (c *WSContext) Locals(key string, defaults ...any) any

func (*WSContext) Logger added in v0.3.0

func (c *WSContext) Logger() logger.Logger

func (*WSContext) TraceID added in v0.5.0

func (c *WSContext) TraceID() string

func (*WSContext) User added in v0.3.0

func (c *WSContext) User() *fs.User

func (*WSContext) WSClient added in v0.3.0

func (c *WSContext) WSClient() fs.WSClient

Jump to

Keyboard shortcuts

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