myhttp

package module
v0.0.0-...-08ba7ff Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: MIT Imports: 11 Imported by: 0

README

myhttp

A simple wrapper for Golang standard http library

Features

  • Graceful shutdown
  • Middlewares
  • Subrouting

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(next http.Handler) http.Handler

func WriteJson

func WriteJson(w http.ResponseWriter, status int, v any) error

Types

type Config

type Config func(*Server)

func Quite

func Quite() Config

func WithAddress

func WithAddress(add string) Config

func WithCustomLogger

func WithCustomLogger(logger *slog.Logger) Config

func WithIdleTimeOut

func WithIdleTimeOut(time time.Duration) Config

func WithReadTimeout

func WithReadTimeout(time time.Duration) Config

func WithTLS

func WithTLS(tlsConfig *tls.Config) Config

func WithWriteTimeout

func WithWriteTimeout(time time.Duration) Config

type Error

type Error struct {
	Status  int
	Message string
}

func (*Error) Error

func (e *Error) Error() string

type Handler

type Handler func(http.ResponseWriter, *http.Request) error

type Middleware

type Middleware func(http.Handler) http.Handler

type Mux

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

func NewMux

func NewMux() *Mux

func (*Mux) Get

func (m *Mux) Get(path string, handler Handler)

func (*Mux) Handle

func (m *Mux) Handle(method string, path string, handler Handler)

func (*Mux) Post

func (m *Mux) Post(path string, handler Handler)

func (*Mux) ServeFile

func (m *Mux) ServeFile(path string, file string)

func (*Mux) ServeFolder

func (m *Mux) ServeFolder(path string, file http.FileSystem)

func (*Mux) Use

func (m *Mux) Use(middle Middleware)

you can't add middleware after calling AddSubRouter

type Server

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

func NewServer

func NewServer(c ...Config) *Server

func (*Server) AddSubRouter

func (s *Server) AddSubRouter(path string, m *Mux)

func (*Server) Get

func (s *Server) Get(path string, handler Handler)

func (*Server) Handle

func (s *Server) Handle(method string, path string, handler Handler)

func (*Server) Post

func (s *Server) Post(path string, handler Handler)

func (*Server) ServeFile

func (s *Server) ServeFile(path string, file string)

func (*Server) ServeFolder

func (s *Server) ServeFolder(path string, file http.FileSystem)

func (*Server) Start

func (s *Server) Start() error

func (*Server) StartWithGracefulShutdown

func (s *Server) StartWithGracefulShutdown(t int, ctx context.Context, fn func() error) error

func (*Server) Use

func (s *Server) Use(m Middleware)

you can't add add middleware after starting the server

Jump to

Keyboard shortcuts

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