goweb

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: MIT Imports: 13 Imported by: 0

README

This just packages up some boilerplate I use in go web projects.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrServerAlreadyStarted = errors.New("server already started")

Functions

func DecodeJSONBody added in v0.1.2

func DecodeJSONBody(w http.ResponseWriter, r *http.Request, dst interface{}) error

func Http405

func Http405(w http.ResponseWriter, allowed ...string)

func HttpXXX

func HttpXXX(w http.ResponseWriter, status int)

Types

type MalformedRequestError added in v0.1.2

type MalformedRequestError struct {
	Msg    string
	Status int
}

func (*MalformedRequestError) Error added in v0.1.2

func (mr *MalformedRequestError) Error() string

func (*MalformedRequestError) Write added in v0.1.2

type Server

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

A wrapper around http.Server with some extra functionality.

func NewServer added in v0.1.2

func NewServer(ctx context.Context, logger *slog.Logger) *Server

func (*Server) EnableProfiler added in v0.1.2

func (s *Server) EnableProfiler(addr string) error

EnableProfiler will cause Start() to also start a net/http/pprof listening at addr. Calling it after Start() returns a ServerAlreadyStartedError.

func (*Server) Handle added in v0.1.2

func (s *Server) Handle(pattern string, handler http.Handler)

func (*Server) HandleFunc added in v0.1.2

func (s *Server) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*Server) Handler added in v0.1.2

func (s *Server) Handler(r *http.Request) (h http.Handler, pattern string)

func (*Server) Start

func (s *Server) Start(listenAddr string) error

func (*Server) Started added in v0.1.2

func (s *Server) Started() bool

func (*Server) Stop added in v0.1.2

func (s *Server) Stop()

Directories

Path Synopsis
middleware module

Jump to

Keyboard shortcuts

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