server

package
v0.0.0-...-bd2d25b Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Response

func Response(w http.ResponseWriter, r *http.Request, statusCode int, body []byte)

Response response by writing the body to http.ResponseWriter. Call at the end line of your handler.

func ResponseJSON

func ResponseJSON(w http.ResponseWriter, r *http.Request, statusCode int, body interface{}) error

ResponseJSON response by writing body with json encoder into http.ResponseWriter. Body must be either struct or map[string]interface{}. Otherwise would result in incorrect parsing at client side. If you have []byte as response body, then use Response function instead. Call at the end line of your handler.

func ResponseString

func ResponseString(w http.ResponseWriter, r *http.Request, statusCode int, body interface{})

ResponseString response in form of string whatever passed into body param. Call at the end line of your handler.

Types

type Cors

type Cors struct {
	AllowedOrigins   []string
	AllowedMethods   []string
	AllowedHeaders   []string
	ExposedHeaders   []string
	MaxAge           int
	AllowCredentials bool
	IsDebug          bool
}

Cors corst options

type Opts

type Opts struct {
	Port uint16

	// EnableLogger enable logging for incoming requests
	EnableLogger bool

	// IdleTimeout keep-alive timeout while waiting for the next request coming. If empty then no timeout.
	IdleTimeout time.Duration

	// Cors optional, can be nil, if nil then default will be set.
	Cors *Cors
}

type Server

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

func New

func New(opts *Opts) *Server

func (*Server) DELETE

func (s *Server) DELETE(path string, handler http.HandlerFunc)

func (*Server) GET

func (s *Server) GET(path string, handler http.HandlerFunc)

func (*Server) HEAD

func (s *Server) HEAD(path string, handler http.HandlerFunc)

func (*Server) ListenError

func (s *Server) ListenError() <-chan error

func (*Server) OPTIONS

func (s *Server) OPTIONS(path string, handler http.HandlerFunc)

func (*Server) PATCH

func (s *Server) PATCH(path string, handler http.HandlerFunc)

func (*Server) POST

func (s *Server) POST(path string, handler http.HandlerFunc)

func (*Server) PUT

func (s *Server) PUT(path string, handler http.HandlerFunc)

func (*Server) Run

func (s *Server) Run()

Run the server. Blocking. Execute it inside goroutine.

Jump to

Keyboard shortcuts

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