Documentation
¶
Overview ¶
Package net provides network-related utilities
Index ¶
- Variables
- type AppRouter
- func (r *AppRouter) Delete(pattern string, handler http.Handler)
- func (r *AppRouter) Get(pattern string, handler http.Handler)
- func (r *AppRouter) Options(pattern string, handler http.Handler)
- func (r *AppRouter) Post(pattern string, handler http.Handler)
- func (r *AppRouter) Put(pattern string, handler http.Handler)
- func (r *AppRouter) Update(pattern string, handler http.Handler)
- func (r *AppRouter) Use(middlewares ...middleware.Middleware)
- type UserContextHelpers
Constants ¶
This section is empty.
Variables ¶
var (
ErrMissingUserContext = errors.New("no user context provided") // ErrMissingUserContext is returned when no context is found while attempting to load user from http.Requests context.
)
Functions ¶
This section is empty.
Types ¶
type AppRouter ¶
type AppRouter struct { *http.ServeMux // ServeMux is an HTTP request multiplexer that matches the URL of each incoming request against a list of registered patterns // contains filtered or unexported fields }
AppRouter is a custom router that embeds the http.ServeMux
func NewAppRouter ¶
NewAppRouter creates a new AppRouter instance with an initialized ServeMux
func (*AppRouter) Use ¶
func (r *AppRouter) Use(middlewares ...middleware.Middleware)
type UserContextHelpers ¶
type UserContextHelpers struct {
R *repository.UserRepository
}
UserContextHelpers provides pluggable helpers to route structures that use, user context within requests.
func (UserContextHelpers) LoadUserFromContext ¶
LoadUserFromContext helper that attempts to read the http.Request's user context key or returns an error if it was not found. Returns the loaded user if found.
func (UserContextHelpers) LoadUserFromContextWithRole ¶
func (h UserContextHelpers) LoadUserFromContextWithRole(r *http.Request, role types.Role) (*models.UserModel, error)
LoadUserFromContextWithRole helper that attempts to read the http.Request's user context key or returns an error if it was not found. Returns the loaded user if found and has the role specified in the parameters. This helper can be used as a gaurd to protect routes being accessed by users without the specified role.
Directories
¶
Path | Synopsis |
---|---|
Package middleware contains HTTP middleware utilities
|
Package middleware contains HTTP middleware utilities |