Documentation
¶
Index ¶
- Variables
- func ApplyErrorHandler[T any, S any](s *Server[S], fn func(req *Request, code Error) T)
- type Csver
- type Error
- type EventStreamHandler
- type EventStreamer
- type FormDataParser
- type Htmler
- type InMemorySessionStore
- type Jsoner
- type Logger
- type Middleware
- type MultipartFormDataParser
- type PlainTextParser
- type Request
- type RequestBody
- type Route
- type Server
- type Session
- type SessionStore
- type SessionStoreContext
- type Sessionless
- type Verb
- type WebsocketHandler
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultLogger defaultLogger
Functions ¶
Types ¶
type EventStreamHandler ¶
type EventStreamHandler func(req *Request) <-chan EventStreamer
type EventStreamer ¶
type EventStreamer interface {
AsEventStream() string
}
type FormDataParser ¶
type InMemorySessionStore ¶
type InMemorySessionStore[T any] struct { Sessions map[string]T // contains filtered or unexported fields }
func NewInMemorySessionStore ¶
func NewInMemorySessionStore[T any]() *InMemorySessionStore[T]
func (InMemorySessionStore[T]) Delete ¶
func (store InMemorySessionStore[T]) Delete(token string) error
func (*InMemorySessionStore[T]) Get ¶
func (store *InMemorySessionStore[T]) Get(token string) (interface{}, error)
func (*InMemorySessionStore[T]) ParseToken ¶
func (store *InMemorySessionStore[T]) ParseToken(header http.Header) string
func (*InMemorySessionStore[T]) Save ¶
func (store *InMemorySessionStore[T]) Save(token string, data interface{}) error
type Middleware ¶
type MultipartFormDataParser ¶
type PlainTextParser ¶
type Request ¶
type Request struct { Session interface{} Verb Verb Path string Headers http.Header Cookies []*http.Cookie Body interface{} // TODO: generic without breaking Request logic? Context context.Context ResponseHeaders http.Header ResponseCode int // contains filtered or unexported fields }
func (*Request) ResponseSize ¶
type RequestBody ¶
func (*RequestBody) ParseFormData ¶
func (body *RequestBody) ParseFormData(rdr io.Reader) *Error
func (*RequestBody) ParseMultipartFormData ¶
func (body *RequestBody) ParseMultipartFormData(rdr io.Reader, boundary string) *Error
type Route ¶
func ApplyRoute ¶
func ApplyRoute[T any, S any, B any](s *Server[S], Path string, body B, handlers map[Verb]func(req *Request) (T, *Error)) *Route[B, T]
You're not able to use generics on a method, so going through a public function which accepts the Server object is the least-bad way to get type safety in the handlers.
func (*Route[B, T]) EventStream ¶
func (r *Route[B, T]) EventStream(handler EventStreamHandler)
func (*Route[B, T]) Middleware ¶
func (r *Route[B, T]) Middleware(mw Middleware)
func (*Route[B, T]) Websocket ¶
func (r *Route[B, T]) Websocket(handler WebsocketHandler)
type Server ¶
type Server[S any] struct { Logger defaultLogger SecureConfig *tls.Config MaxPostSize uint // contains filtered or unexported fields }
func New ¶
func New[S any](sessionStore SessionStore) *Server[S]
func (*Server[S]) Middleware ¶
func (s *Server[S]) Middleware(mw Middleware)
func (*Server[S]) PublicRoute ¶
func (*Server[S]) RegisterContentTypeInterface ¶
type SessionStore ¶
type SessionStore interface { ParseToken(http.Header) string Get(token string) (interface{}, error) Save(token string, data interface{}) error Delete(token string) error }
Sessions could be via Cookies Stored in DB Stored in memory
type SessionStoreContext ¶
type Sessionless ¶
type Sessionless struct{}
Sessionless is a placeholder for anyone who wants to run a sessionless-server
func (Sessionless) Delete ¶
func (_ Sessionless) Delete(token string) error
func (Sessionless) Get ¶
func (_ Sessionless) Get(token string) (interface{}, error)
func (Sessionless) ParseToken ¶
func (_ Sessionless) ParseToken(header http.Header) string
func (Sessionless) Save ¶
func (_ Sessionless) Save(token string, data interface{}) error
type WebsocketHandler ¶
Click to show internal directories.
Click to hide internal directories.