minisrv

package module
v0.0.0-...-890733b Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

minsrv

MiniSrv is a thin wrapper around Go's HTTP server

http server:

func main() {
    minisrv.NewHTTPServer().
    AddRoute(route).
    AddMiddleware(middleware).
    ListenAndServe() // or ListenAndServe(":8082")
}
Route
// mux route
func route(m *mux.Router) {
    m.HandleFunc("/", indexHandler)
    m.HandleFunc("/health", healthHandler)
    m.HandleFunc("/api/v1/actid/%d", func(w http.ResponseWriter, req *http.Request) {
        fmt.Fprintf(w, "Welcome to the actid page!")
    })
}
Middeleware
func middleware(n *negroni.Negroni) {
    n.Use(negroni.HandlerFunc(Authorizer))
    n.Use(negroni.HandlerFunc(APIMiddleware))
}

Thanks

package type
https://github.com/gorilla/mux Route
https://github.com/urfave/negroni Middeleware

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPServer

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

func NewHTTPServer

func NewHTTPServer() *HTTPServer

func (*HTTPServer) AddMiddleware

func (s *HTTPServer) AddMiddleware(f MiddlewareFunc) *HTTPServer

func (*HTTPServer) AddRoute

func (s *HTTPServer) AddRoute(f RouteFunc) *HTTPServer

func (*HTTPServer) ListenAndServe

func (s *HTTPServer) ListenAndServe(addrs ...string) error

func (*HTTPServer) Shutdown

func (s *HTTPServer) Shutdown(ctx context.Context)

gracefully shutdown the server, waiting max 30 seconds for current operations to complete ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)

func (*HTTPServer) WithReadTimeout

func (s *HTTPServer) WithReadTimeout(dur time.Duration)

func (*HTTPServer) WithWriteTimeout

func (s *HTTPServer) WithWriteTimeout(dur time.Duration)

type MiddlewareFunc

type MiddlewareFunc func(m *negroni.Negroni)

type RouteFunc

type RouteFunc func(m *mux.Router)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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