web

package
v0.0.0-...-a46cd05 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseSessionStore

type BaseSessionStore struct {
	DataBuffer map[string]any
}

func NewBaseSessionStore

func NewBaseSessionStore() *BaseSessionStore

func (*BaseSessionStore) Buffer

func (s *BaseSessionStore) Buffer() map[string]any

func (*BaseSessionStore) Del

func (s *BaseSessionStore) Del(key string)

func (*BaseSessionStore) Get

func (s *BaseSessionStore) Get(key string) (any, bool)

func (*BaseSessionStore) Reset

func (s *BaseSessionStore) Reset()

func (*BaseSessionStore) Set

func (s *BaseSessionStore) Set(key string, value any)

type Context

type Context struct {
	// server handler
	Server *Server
	// log handler for request
	Logger *xlog.Logger
	// request handler
	Request *Request

	// session store
	Session SessionStore
}

type Request

type Request struct {
	*http.Request
}

func (*Request) IsJson

func (r *Request) IsJson() bool

check json or xhr/ajax request type

func (*Request) IsXhr

func (r *Request) IsXhr() bool

check xhr/ajax request type

type Response

type Response struct {
	Headers     map[string]string
	Cookies     map[string]*http.Cookie
	Content     []byte
	RedirectUrl string
	StatusCode  int
}

func ErrorResponse

func ErrorResponse(errmsg string, code int) *Response

func NewResponse

func NewResponse(content string) *Response

func RedirectResponse

func RedirectResponse(url string) *Response

func (*Response) Append

func (r *Response) Append(content string)

add new contents to end of current content

func (*Response) DelCookie

func (r *Response) DelCookie(name string)

set/edit cookie to be deleted, adjust MaxAge=-1

func (*Response) DelHeader

func (r *Response) DelHeader(key string)

delete response header field from buffer

func (*Response) FlushCookies

func (r *Response) FlushCookies()

delete all response cookie fields from buffer

func (*Response) FlushHeaders

func (r *Response) FlushHeaders()

delete all response header fields from buffer

func (*Response) Prepend

func (r *Response) Prepend(content string)

add new contents at begining of current content

func (*Response) SetCookie

func (r *Response) SetCookie(cookie *http.Cookie)

set/create new response cookie in buffer

func (*Response) SetHeader

func (r *Response) SetHeader(key string, val string)

add/edit response header field in buffer

type Server

type Server struct {
	Name      string
	Logger    *xlog.Logger
	Reqlogger *xlog.Logger

	// server session factory
	SessionFactory SessionFactory

	// path for serving static contents
	StaticPath string
	// max request content length
	MaxContentLength int
	// default response content type
	DefaultContentType string
	// contains filtered or unexported fields
}

func NewServer

func NewServer(name string, opts map[string]any) *Server

func (*Server) AddView

func (s *Server) AddView(view View)

func (*Server) Start

func (s *Server) Start(host string, port int) error

func (*Server) Stop

func (s *Server) Stop() error

type SessionCookieFactory

type SessionCookieFactory struct {
	SecretKey      string
	CookieName     string
	CookiePath     string
	CookieDomain   string
	CookieMaxAge   int
	CookieSecure   bool
	CookieHttpOnly bool
	CookieSameSite http.SameSite
}

session cookie factory, saves session data in browser cookies

func NewSessionCookieFactory

func NewSessionCookieFactory(opts map[string]any) *SessionCookieFactory

func (*SessionCookieFactory) Create

type SessionCookieStore

type SessionCookieStore struct {
	*BaseSessionStore
	// contains filtered or unexported fields
}

func (*SessionCookieStore) Load

func (s *SessionCookieStore) Load() error

func (*SessionCookieStore) Purge

func (s *SessionCookieStore) Purge() error

func (*SessionCookieStore) Save

func (s *SessionCookieStore) Save() error

type SessionFactory

type SessionFactory interface {
	// create new session store handler
	Create(*http.Request, http.ResponseWriter) SessionStore
}

type SessionFileFactory

type SessionFileFactory struct {
	SecretKey      string
	CookieName     string
	CookiePath     string
	CookieDomain   string
	CookieMaxAge   int
	CookieSecure   bool
	CookieHttpOnly bool
	CookieSameSite http.SameSite
	StorePath      string
}

session file factory, saves session data in server side files

func NewSessionFileFactory

func NewSessionFileFactory(opts map[string]any) *SessionFileFactory

func (*SessionFileFactory) Create

type SessionFileStore

type SessionFileStore struct {
	*BaseSessionStore
	// contains filtered or unexported fields
}

func (*SessionFileStore) Load

func (s *SessionFileStore) Load() error

func (*SessionFileStore) Purge

func (s *SessionFileStore) Purge() error

func (*SessionFileStore) Save

func (s *SessionFileStore) Save() error

type SessionStore

type SessionStore interface {
	// load data from session actual store into data buffer
	Load() error
	// save data from data buffer into session actual store
	Save() error
	// delete all data buffer and session actual store
	Purge() error

	// return the whole internal data buffer
	Buffer() map[string]any
	// get item by key from data buffer
	Get(string) (any, bool)
	// set item by key in data buffer
	Set(string, any)
	// delete item by key from data buffer
	Del(string)
	// reset data buffer, delete all keys
	Reset()
}

type View

type View interface {
	Meta() *ViewMeta
}

type ViewAfterRequest

type ViewAfterRequest interface {
	AfterRequest(*Context, *Response) *Response
}

type ViewBeforeRequest

type ViewBeforeRequest interface {
	BeforeRequest(*Context) *Response
}

type ViewDispatchRequest

type ViewDispatchRequest interface {
	DispatchRequest(*Context) *Response
}

type ViewDoDelete

type ViewDoDelete interface {
	DoDelete(*Context) *Response
}

type ViewDoGet

type ViewDoGet interface {
	DoGet(*Context) *Response
}

type ViewDoHead

type ViewDoHead interface {
	DoHead(*Context) *Response
}

type ViewDoPatch

type ViewDoPatch interface {
	DoPatch(*Context) *Response
}

type ViewDoPost

type ViewDoPost interface {
	DoPost(*Context) *Response
}

type ViewDoPut

type ViewDoPut interface {
	DoPut(*Context) *Response
}

type ViewHandleRequest

type ViewHandleRequest interface {
	HandleRequest(*Context) *Response
}

type ViewMeta

type ViewMeta struct {
	Name   string
	Routes []string
}

func NewViewMeta

func NewViewMeta(name string, routes ...string) *ViewMeta

Jump to

Keyboard shortcuts

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