webserver

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 12 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, certFile, keyFile string, handler Handler) error

func NewError added in v0.3.0

func NewError(log any) *serverError

func NewHTTPError

func NewHTTPError(statusCode int, log any) *serverError

func Serve added in v0.2.0

func Serve(l net.Listener, handler Handler) error

func ServeTLS added in v0.2.0

func ServeTLS(l net.Listener, handler Handler, certFile string, keyFile string) error

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) Float32Param

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

func (*Request) Float64Param

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

func (*Request) Header

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

func (*Request) Headers

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

func (*Request) IntParam

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

func (*Request) IsDone

func (this *Request) IsDone() bool

func (*Request) Param

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

func (*Request) Params

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

func (*Request) UIntParam

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

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 {
	// 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 Handler) *Server

func (*Server) Delete

func (this *Server) Delete(pattern string, webserverHandler Handler) *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 Handler) *Server

func (*Server) Handle

func (this *Server) Handle(method string, pattern string, handler Handler) *Server

func (*Server) HandleAll

func (this *Server) HandleAll(pattern string, webserverHandler Handler) *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 Handler) *Server

func (*Server) Post

func (this *Server) Post(pattern string, webserverHandler Handler) *Server

func (*Server) Put

func (this *Server) Put(pattern string, webserverHandler Handler) *Server

func (*Server) Render

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

func (*Server) Serve added in v0.2.0

func (this *Server) Serve(l net.Listener) error

func (*Server) ServeTLS added in v0.2.0

func (this *Server) ServeTLS(l net.Listener, certFile string, keyFile string) error

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