Version: v0.0.0-...-d9a1202 Latest Latest

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

Go to latest
Published: Jan 22, 2019 License: MIT Imports: 14 Imported by: 0




View Source
const (
	// CommonFormatPattern is the Apache Common Log format.
	CommonFormatPattern = "%s - %s [%s] \"%s\" %d %d\n"


This section is empty.


func AccessLogger

func AccessLogger(handler http.Handler, e bool) http.HandlerFunc

AccessLogger configures a HTTP access log for a web server. Using this middleware uses the Apache common logger as the default log entry.

func CORS

func CORS(h http.Handler) http.Handler

CORS function handles Cross Origin Request headers.

func Recovery

func Recovery(h http.Handler) http.Handler

Recovery function handles the logging of panics if the web server encounters a error. Once the error is logged, the server will respond with a 500 error code to the client.

func RegisterRoutes

func RegisterRoutes() *httprouter.Router

RegisterRoutes sets all the configured routes for the server to the designated handler and middleware.

func SimpleMiddleware

func SimpleMiddleware(h http.Handler) http.Handler

SimpleMiddleware is just an example logging middleware.

func Start

func Start(c Config) error

Start sets up and starts the main server application


type Config

type Config struct {
	LogLvl string
	Access bool
	Port   string
	PID    string
	TLS    bool
	Cert   string
	Key    string

Config struct provides configuration fields for the server.

type LogRequest

type LogRequest struct {
	Time                                            time.Time
	RemoteIP, Method, URI, Protocol, Username, Host string
	Status                                          int
	ResponseBytes                                   int
	ElapsedTime                                     time.Duration
	RequestHeader                                   http.Header

LogRequest describes a request that is made into the server.

func (*LogRequest) Write

func (w *LogRequest) Write(b []byte) (int, error)

Write writes a header in wireformat, this function is overridden so that AccessLogger can log the HTTP status.

func (*LogRequest) WriteHeader

func (w *LogRequest) WriteHeader(status int)

WriteHeader overrides the default WriteHeader function so that you can log HTTP statues.

type Pidfile

type Pidfile struct {
	Name string

Pidfile is a struct that describes a PID file.

func CreatePID

func CreatePID(name string) *Pidfile

CreatePID creates a new PID file.

func (*Pidfile) RemovePID

func (pf *Pidfile) RemovePID()

RemovePID removes the PID file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL