webserver

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeHeader = "Content-Type"

	ContentTypeFormUrlEncoded = "application/x-www-form-urlencoded"
	ContentTypeFormData       = "multipart/form-data"
	ContentTypeJson           = "application/json"
	ContentTypeEventStream    = "text/event-stream"
)

Variables

View Source
var EventStreamHeader = map[string][]string{
	ContentTypeHeader: {ContentTypeEventStream},
	"Cache-Control":   {"no-cache"},
	"Connection":      {"keep-alive"},
}

Functions

func ListenAndServe

func ListenAndServe(addr string, handler Handler) error

func ListenAndServeTLS

func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler) error

func NewHTTPError

func NewHTTPError(statusCode int, log any) *serverError

Types

type Event

type Event struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Data any    `json:"data"`
}

func (*Event) ToBytes

func (this *Event) ToBytes() []byte

func (*Event) ToString

func (this *Event) ToString() string

type Handler

type Handler func(req *Request, res *Response)

type Request

type Request struct {
	Raw *http.Request
	// contains filtered or unexported fields
}

func (*Request) AllFiles

func (this *Request) AllFiles() map[string][]*multipart.FileHeader

func (*Request) AllHeaders

func (this *Request) AllHeaders() http.Header

func (*Request) AllParams

func (this *Request) AllParams() map[string][]string

func (*Request) Body

func (this *Request) Body() []byte

func (*Request) File

func (this *Request) File(paramName string) *multipart.FileHeader

func (*Request) Files

func (this *Request) Files(paramName string) []*multipart.FileHeader

func (*Request) Header

func (this *Request) Header(name string) string

func (*Request) Headers

func (this *Request) Headers(name string) []string

func (*Request) IsDone

func (this *Request) IsDone() bool

func (*Request) Param

func (this *Request) Param(paramName string) string

func (*Request) ParamFloat32

func (this *Request) ParamFloat32(paramName string) float32

func (*Request) ParamFloat64

func (this *Request) ParamFloat64(paramName string) float64

func (*Request) ParamInt

func (this *Request) ParamInt(paramName string) int

func (*Request) ParamUInt

func (this *Request) ParamUInt(paramName string) uint

func (*Request) Params

func (this *Request) Params(paramName string) []string

type Response

type Response struct {
	RawWriter http.ResponseWriter
	RawFS     http.FileSystem
	// contains filtered or unexported fields
}

func (*Response) Flush

func (this *Response) Flush(data []byte) error

func (*Response) FlushEvent

func (this *Response) FlushEvent(event *Event) error

func (*Response) FlushText

func (this *Response) FlushText(text string) error

func (*Response) Header

func (this *Response) Header(key, value string) *Response

func (*Response) Headers

func (this *Response) Headers(headers map[string][]string) *Response

func (*Response) MustSupportFlusher

func (this *Response) MustSupportFlusher()

func (*Response) NoBody

func (this *Response) NoBody()

func (*Response) Render

func (this *Response) Render(filePath string)

func (*Response) Status

func (this *Response) Status(status int) *Response

func (*Response) SupportFlusher

func (this *Response) SupportFlusher() bool

func (*Response) View

func (this *Response) View(key string, value string) *Response

func (*Response) Write

func (this *Response) Write(data []byte)

func (*Response) WriteJSON

func (this *Response) WriteJSON(value any)

func (*Response) WriteText

func (this *Response) WriteText(text string)

type Server

type Server struct {
	http.ServeMux
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func NewServerWithFS

func NewServerWithFS(fileSystem http.FileSystem) *Server

func (*Server) All

func (this *Server) All(pattern string, webserverHandler func(req *Request, res *Response)) *Server

func (*Server) Delete

func (this *Server) Delete(pattern string, webserverHandler func(req *Request, res *Response)) *Server

func (*Server) FileServer

func (this *Server) FileServer(pattern string)

func (*Server) FileServerStrippingPrefix

func (this *Server) FileServerStrippingPrefix(pattern string, stripPrefix string)

func (*Server) Get

func (this *Server) Get(pattern string, webserverHandler func(req *Request, res *Response)) *Server

func (*Server) Handle

func (this *Server) Handle(method string, pattern string, handler func(req *Request, res *Response)) *Server

func (*Server) HandleAll

func (this *Server) HandleAll(pattern string, webserverHandler func(req *Request, res *Response)) *Server

func (*Server) ListenAndServe

func (this *Server) ListenAndServe(addr string) error

func (*Server) ListenAndServeTLS

func (this *Server) ListenAndServeTLS(addr, certFile, keyFile string) error

func (*Server) MultiHandle

func (this *Server) MultiHandle(methods []string, pattern string, handler func(req *Request, res *Response)) *Server

func (*Server) Post

func (this *Server) Post(pattern string, webserverHandler func(req *Request, res *Response)) *Server

func (*Server) Put

func (this *Server) Put(pattern string, webserverHandler func(req *Request, res *Response)) *Server

func (*Server) Render

func (this *Server) Render(pattern string, filePath string) *Server

func (*Server) Write

func (this *Server) Write(pattern string, data []byte) *Server

func (*Server) WriteJSON

func (this *Server) WriteJSON(pattern string, filePath string) *Server

func (*Server) WriteText

func (this *Server) WriteText(pattern string, text string) *Server

Jump to

Keyboard shortcuts

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