net

package
v0.0.0-...-68e8b16 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package net provides network-related utilities

Index

Constants

This section is empty.

Variables

View Source
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

func NewAppRouter(lw logging.LogWriter) AppRouter

NewAppRouter creates a new AppRouter instance with an initialized ServeMux

func (*AppRouter) Delete

func (r *AppRouter) Delete(pattern string, handler http.Handler)

Delete registers a handler for DELETE requests with the given pattern

func (*AppRouter) Get

func (r *AppRouter) Get(pattern string, handler http.Handler)

Get registers a handler for GET requests with the given pattern

func (*AppRouter) Options

func (r *AppRouter) Options(pattern string, handler http.Handler)

Options registers a handler for OPTIONS requests with the given pattern

func (*AppRouter) Post

func (r *AppRouter) Post(pattern string, handler http.Handler)

Post registers a handler for POST requests with the given pattern

func (*AppRouter) Put

func (r *AppRouter) Put(pattern string, handler http.Handler)

Put registers a handler for PUT requests with the given pattern

func (*AppRouter) Update

func (r *AppRouter) Update(pattern string, handler http.Handler)

Update registers a handler for UPDATE requests with the given pattern

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

func (h UserContextHelpers) LoadUserFromContext(r *http.Request) (*models.UserModel, error)

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

Jump to

Keyboard shortcuts

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