web

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: AGPL-3.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// OrgIDKey is our context key for org id
	OrgIDKey = "org_id"

	// UserIDKey is our context key for user id
	UserIDKey = "user_id"

	// MaxRequestBytes is the max body size our web server will accept
	MaxRequestBytes int64 = 1048576
)

Variables

This section is empty.

Functions

func DecodeAndValidateForm added in v0.0.74

func DecodeAndValidateForm(form interface{}, r *http.Request) error

DecodeAndValidateForm takes the passed in form and attempts to parse and validate it from the URL query parameters as well as any POST parameters of the passed in request

func RegisterJSONRoute added in v0.0.74

func RegisterJSONRoute(method string, pattern string, handler JSONHandler)

func RegisterRoute added in v0.0.74

func RegisterRoute(method string, pattern string, handler Handler)

func Validate added in v0.0.74

func Validate(form interface{}) error

Validate validates the passe din struct using our shared validator instance

Types

type Handler added in v0.0.74

type Handler func(ctx context.Context, s *Server, r *http.Request, w http.ResponseWriter) error

type JSONHandler

type JSONHandler func(ctx context.Context, s *Server, r *http.Request) (interface{}, int, error)

func RequireAuthToken added in v0.0.74

func RequireAuthToken(handler JSONHandler) JSONHandler

RequireAuthToken wraps a handler to require that our request to have our global authorization header

func RequireUserToken added in v0.0.74

func RequireUserToken(handler JSONHandler) JSONHandler

type Server

type Server struct {
	CTX      context.Context
	RP       *redis.Pool
	DB       *sqlx.DB
	S3Client s3iface.S3API
	Config   *config.Config
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx context.Context, config *config.Config, db *sqlx.DB, rp *redis.Pool, s3Client s3iface.S3API, wg *sync.WaitGroup) *Server

NewServer creates a new web server, it will need to be started after being created

func (*Server) Start

func (s *Server) Start()

Start starts our web server, listening for new requests

func (*Server) Stop

func (s *Server) Stop()

Stop stops our web server

func (*Server) WrapHandler added in v0.0.74

func (s *Server) WrapHandler(handler Handler) http.HandlerFunc

WrapHandler wraps a simple Handler, taking care of passing down server and handling errors

func (*Server) WrapJSONHandler added in v0.0.74

func (s *Server) WrapJSONHandler(handler JSONHandler) http.HandlerFunc

WrapJSONHandler wraps a simple JSONHandler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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