we

package module
v1.0.0-b8 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 8 Imported by: 4

README

go-we

WORK In Progress.

Documentation

Overview

Go-We (pronounced "go wheeee!)" is an http web engine that can be used to have common use-cases in place, for example http Session management, rest variable parsing, wildcard path handling, request filtering or authenticated endpoints.

The webEngine itself implements the http.Handler interface and can be typically used instead of the DefaultServeMux

Index

Constants

View Source
const (
	// DefaultSessionTimeout Default duration of an idle/active session
	DefaultSessionTimeout = time.Hour
	// DefaultCookieName default cookie name set with the session id
	DefaultCookieName = "weSessionId"
	// DefaultPurgeInterval default session purge interval
	DefaultPurgeInterval = time.Minute
)

Session management constants

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler interface {
	HandleError(ResponseWriter, error, RequestScope)
}

type ErrorMarshaller

type ErrorMarshaller interface {
	Marshal(error) ([]byte, string)
}

type Filter

type Filter interface {
	Filter(http.Header, RequestScope) error
}

type FilterFunction

type FilterFunction func(http.Header, RequestScope) error

func (FilterFunction) Filter

func (ff FilterFunction) Filter(headers http.Header, scope RequestScope) error

type HandlerFunction

type HandlerFunction func(ResponseWriter, RequestScope) error

type Headers

type Headers interface {
}

type RequestScope

type RequestScope interface {
	Request() *http.Request
	Var(string) string
	LookupVar(string) (string, bool)
	Parameter(string) string
	Parameters(string) []string
	LookupParameter(string) (string, bool)
	LookupParameters(string) ([]string, bool)
	Get(string) interface{}
	Set(string, interface{})
	GetFromSession(string) interface{}
	SetInSession(string, interface{})
	HasSession() bool
}

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	// contains filtered or unexported methods
}

type Session

type Session struct {
	// If the Session has just been created or if it's an existing one
	Status uint

	// Timestamp of last Session use
	LastUse time.Time

	// Unique Session id
	Id string

	// Payloads stored in the Session. Retrieval and use of context payloads are implementation specific.
	Attributes map[string]interface{}
}

Session object associated to a request (either the request comes with a Session identifier or it is created for the request

type SessionManager

type SessionManager interface {
	// GetHttpSession gets an existing http session from storage. Non-existing, expired or mismatched session-ids should
	// result in a new session and set in the response
	GetHttpSession(w http.ResponseWriter, r *http.Request) *Session
}

SessionManager manages a Session life-cycle

func DefaultSessionManager

func DefaultSessionManager(configuration SessionManagerConfiguration) SessionManager

DefaultSessionManager provides a default in-memory Session manager

type SessionManagerConfiguration

type SessionManagerConfiguration struct {
	// Allows providing a custom session storage. When nil the session manager will use the inMemory session storage
	Storage SessionStorage
	// The maximum duration of an idle/active session
	SessionTimeout time.Duration
	// Boolean setting the expiration type to use. If false, the timeout of a session is refreshed
	// after each access, if true a new session has a fixed duration, regardless if it's idle or not.
	StaticSessionLifespan bool
	// The cookie name to be used when setting it in the browser. Defaults to "weSessionId"
	CookieName string
	// Interval at which purging process checks for expired sessions and cleans them from storage
	SessionPurgingInterval time.Duration
}

SessionManagerConfiguration Configuration settings for the default session manager

type SessionStorage

type SessionStorage interface {
	// Get retrieves a session by its session id. nil if none is found
	Get(sessionId string) *Session
	// Put stores/updates a session object, returns the existing object if updating or nil if new
	Put(session *Session) *Session
	// Delete deletes a session object referenced by its id. Return nil if no session is deleted.
	Delete(sessionId string) *Session
	// PurgeOlderThan deletes from storage all sessions older than <age>
	PurgeOlderThan(age time.Duration)
}

SessionStorage interface for a session storage service

type WebEngine

type WebEngine interface {
	SetSessionManager(sessionManager SessionManager)
	Handle(path string, handler HandlerFunction)
	HandleMethod(method string, path string, handler HandlerFunction)
	AddFilter(filter Filter)
	Listen(addr string) error
	Handler() http.Handler
}

func New

func New() WebEngine

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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