server

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 14 Imported by: 0

README

	// initialize with empty cors setting
        rtr := server.New([]string{})

	// sample custom middleware
        rtr.Use(func (next http.Handler) http.Handler {
                return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                        next.ServeHTTP(w, r)
                })
        })

	// use "esc" to create a "codified" version of static files and declare like this
	// https://github.com/mjibson/esc
	// for example ~/go/bin/esc -o testdir/test.go -pkg static -ignore=".*.go" testdir
        rtr.StaticFs("/test/", static.FS(false))

	// api definition
        rtr.Get("/welcome", func(w http.ResponseWriter, r *http.Request) {
                server.JSON(w, r, map[string]string{
                        "status": "success",
                })
        })

	// run server with cleartext http/2
        rtr.Run("h2c", ":8080")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(w http.ResponseWriter, r *http.Request, v interface{})

JSON - send a json response

func URLParam

func URLParam(r *http.Request, p string) string

URLParam - return value of a url parameter

Types

type ChiRouter added in v0.0.3

type ChiRouter = chi.Router

ChiRouter - interface for chi router

type Router

type Router struct {
	Engine *chi.Mux
	// contains filtered or unexported fields
}

Router - initialized instance

func New

func New(origins []string, headers []string) (*Router, error)

New - constructor function to initialize instance

func (Router) Delete

func (rtr Router) Delete(route string, handler http.HandlerFunc)

Delete - implementation of http delete

func (Router) Get

func (rtr Router) Get(route string, handler http.HandlerFunc)

Get - implementation of http get

func (Router) Patch

func (rtr Router) Patch(route string, handler http.HandlerFunc)

Patch - implementation of http patch

func (Router) Post

func (rtr Router) Post(route string, handler http.HandlerFunc)

Post - implementation of http post

func (Router) Put

func (rtr Router) Put(route string, handler http.HandlerFunc)

Put - implementation of http put

func (Router) Run

func (rtr Router) Run(proto string, hostport string) error

Run - run and listen for http

func (Router) RunS

func (rtr Router) RunS(proto string, hostport string, crt string, key string) error

RunS - run and listen for https

func (*Router) SetLogRequest

func (rtr *Router) SetLogRequest(lr bool)

SetLogRequest - changes behaviour on whether to log requests or not

func (*Router) SetLogSkipPath added in v0.1.1

func (rtr *Router) SetLogSkipPath(list []string)

SetLogSkipPath - changes the middleware logging behaviour

func (*Router) SetLogger

func (rtr *Router) SetLogger(logtype string)

SetLogger - changes the logger mode

func (Router) Static

func (rtr Router) Static(urlPath string, dirPath string)

Static - function to handle and serve static files within a directory on live system

func (Router) StaticFs

func (rtr Router) StaticFs(urlPath string, fs http.FileSystem)

StaticFs - function to handle and serve static files embedded into binary using esc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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