fmk

package module
v0.0.0-...-2c83b2f Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2019 License: MIT Imports: 19 Imported by: 0

README

fmk

AW Web Framework for go

Documentation

Index

Constants

View Source
const (
	SIDBaseLen      int = 32
	CipherKeyLength int = 32
)
View Source
const (
	FRONT_SLASH = 47 // literally ascii/utf8 for '/'
)

Variables

View Source
var (
	DEFAULT_READ_TIMEOUT  = time.Duration(5) * time.Second
	DEFAULT_WRITE_TIMEOUT = time.Duration(30) * time.Second
	DEFAULT_IDLE_TIMEOUT  = time.Duration(240) * time.Second
)
View Source
var (
	ALPHA              []byte = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
	DefaultSessionName string = "FMKSession"
	DefaultSessionKey  []byte = []byte("PleaseChangeMe;MoreRandom=Better")
	SIDInUse           error  = errors.New("SID In Use")
	SIDMissing         error  = errors.New("SID Missing")

	SIDBaseString string = "Kitty"
	BadSID        error  = errors.New("Invalid SID")

	LenMismatch     error = errors.New("Mismatched Length")
	KeyTooShort     error = errors.New("KeyTooShort")
	SessionKeyUnset error = errors.New("Session Key Unset")
)
View Source
var (
	CipherTextTooShort error = errors.New("FMK: Ciphertext too short")
)
View Source
var (
	DEFAULT_COPY_BUFFER_SIZE = 4096
)
View Source
var DefaultMessages = map[int][]byte{
	http.StatusOK:                  []byte("OK\n"),
	http.StatusNotFound:            []byte("Not Found\n"),
	http.StatusUnauthorized:        []byte("Unauthorized\n"),
	http.StatusNotAcceptable:       []byte("Not Acceptable\n"),
	http.StatusLengthRequired:      []byte("Length Required\n"),
	http.StatusMethodNotAllowed:    []byte("Method Not Allowed\n"),
	http.StatusInternalServerError: []byte("Internal Server Error\n"),
	http.StatusExpectationFailed:   []byte("Expectation Failed\n"),
}

Functions

func DefaultWrapper

func DefaultWrapper(orig func(http.ResponseWriter, *http.Request) int) func(http.ResponseWriter, *http.Request)

func LogInit

func LogInit(
	traceHandle io.Writer,
	infoHandle io.Writer,
	warningHandle io.Writer,
	errorHandle io.Writer)

func ParseURL

func ParseURL(url string) []string

func ReplaceBoolWithEnv

func ReplaceBoolWithEnv(spot *bool, key string) (err error)

func ReplaceIntWithEnv

func ReplaceIntWithEnv(spot *int, key string) (err error)

func ReplaceStringWithEnv

func ReplaceStringWithEnv(spot *string, key string) (err error)

func RespondExpectationFailed

func RespondExpectationFailed(respWriter http.ResponseWriter, req *http.Request) int

func RespondInternalServerError

func RespondInternalServerError(respWriter http.ResponseWriter, req *http.Request) int

func RespondLengthRequired

func RespondLengthRequired(respWriter http.ResponseWriter, req *http.Request) int

func RespondMethodNotAllowed

func RespondMethodNotAllowed(respWriter http.ResponseWriter, req *http.Request) int

func RespondNotAcceptable

func RespondNotAcceptable(respWriter http.ResponseWriter, req *http.Request) int

func RespondNotFound

func RespondNotFound(respWriter http.ResponseWriter, req *http.Request) int

func RespondOK

func RespondOK(respWriter http.ResponseWriter, req *http.Request) int

func RespondOKWithBody

func RespondOKWithBody(body []byte, respWriter http.ResponseWriter, req *http.Request) int

func RespondOKWithReader

func RespondOKWithReader(r io.Reader, respWriter http.ResponseWriter, req *http.Request) int

func RespondTemporaryRedirect

func RespondTemporaryRedirect(respWriter http.ResponseWriter, req *http.Request, url string) int

func RespondUnauthorized

func RespondUnauthorized(respWriter http.ResponseWriter, req *http.Request) int

func RespondWithBody

func RespondWithBody(body []byte, code int, respWriter http.ResponseWriter, req *http.Request) int

func RespondWithReader

func RespondWithReader(r io.Reader, code int, respWriter http.ResponseWriter, req *http.Request) int

Types

type FmkSession

type FmkSession struct {
	Book        map[string]string
	SID         string
	DomainName  string
	Path        string
	SessionName string
	LastUpdate  time.Time
}

func (*FmkSession) Del

func (sess *FmkSession) Del(key string) error

func (*FmkSession) Get

func (sess *FmkSession) Get(key string) string

func (*FmkSession) GetCookie

func (sess *FmkSession) GetCookie() *http.Cookie

func (*FmkSession) GetLastUpdate

func (sess *FmkSession) GetLastUpdate() time.Time

func (*FmkSession) SessionID

func (sess *FmkSession) SessionID() string

func (*FmkSession) Set

func (sess *FmkSession) Set(key, value string) error

func (*FmkSession) Update

func (sess *FmkSession) Update()

type FmkSessionManager

type FmkSessionManager struct {
	SessionName string

	SessionKey []byte
	DomainName string
	Path       string

	Lock           sync.Mutex
	SessionMaxLife time.Duration
	GCRate         time.Duration
	Book           map[string]Session
}

func NewSessionManager

func NewSessionManager(sessionName string, sml, gcrate time.Duration) *FmkSessionManager

func (*FmkSessionManager) GC

func (sm *FmkSessionManager) GC()

func (*FmkSessionManager) GetSession

func (sm *FmkSessionManager) GetSession(writer http.ResponseWriter, req *http.Request) (Session, error)

func (*FmkSessionManager) SetGCRate

func (sm *FmkSessionManager) SetGCRate(gcRate time.Duration)

func (*FmkSessionManager) SetSessionDomain

func (sm *FmkSessionManager) SetSessionDomain(domainName string)

func (*FmkSessionManager) SetSessionKey

func (sm *FmkSessionManager) SetSessionKey(sessionKey []byte)

func (*FmkSessionManager) SetSessionMaxLife

func (sm *FmkSessionManager) SetSessionMaxLife(ml time.Duration)

func (*FmkSessionManager) SetSessionName

func (sm *FmkSessionManager) SetSessionName(sessionName string)

func (*FmkSessionManager) SetSessionPath

func (sm *FmkSessionManager) SetSessionPath(path string)

func (*FmkSessionManager) Sign

func (sm *FmkSessionManager) Sign(base string) string

func (*FmkSessionManager) Validate

func (sm *FmkSessionManager) Validate(sid string) error

type FmkWebServer

type FmkWebServer struct {
	ReadTimeout  *time.Duration
	WriteTimeout *time.Duration
	IdleTimeout  *time.Duration
	// contains filtered or unexported fields
}
var Server FmkWebServer

func (*FmkWebServer) FixTimeouts

func (ws *FmkWebServer) FixTimeouts()

func (*FmkWebServer) HandleFunc

func (ws *FmkWebServer) HandleFunc(path string, handleFunc func(http.ResponseWriter, *http.Request) int)

func (*FmkWebServer) Listen

func (ws *FmkWebServer) Listen(address string, port int) error

func (*FmkWebServer) ServeStatic

func (ws *FmkWebServer) ServeStatic(staticDir, pathRoot string)

func (*FmkWebServer) SetDefaultWrapper

func (ws *FmkWebServer) SetDefaultWrapper(wf WrapperFunc)

func (*FmkWebServer) SetTLSConf

func (ws *FmkWebServer) SetTLSConf(conf *tls.Config)

func (*FmkWebServer) SetTLSServing

func (ws *FmkWebServer) SetTLSServing(certPath, keyPath string)

type Logger

type Logger struct {
	Trace   *log.Logger
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
}
var Log Logger

func (*Logger) SetError

func (logger *Logger) SetError(w io.Writer)

func (*Logger) SetInfo

func (logger *Logger) SetInfo(w io.Writer)

func (*Logger) SetTrace

func (logger *Logger) SetTrace(w io.Writer)

func (*Logger) SetWarning

func (logger *Logger) SetWarning(w io.Writer)

type Session

type Session interface {
	Set(key, value string) error
	Get(key string) string
	Del(key string) error
	SessionID() string
	GetLastUpdate() time.Time
	Update()
	GetCookie() *http.Cookie
}

func NewSession

func NewSession(sid, domain, path, sessionName string) Session

type SessionManager

type SessionManager interface {
	GetSession(respWriter http.ResponseWriter, req *http.Request) (Session, error)

	SetSessionKey(sessionKey []byte)
	SetSessionName(sessionName string)
	SetSessionDomain(domainName string)
	SetSessionPath(pathName string)
	SetGCRate(gcRate time.Duration)
	SetSessionMaxLife(ml time.Duration)
	// contains filtered or unexported methods
}
var Sessions SessionManager

type WebServer

type WebServer interface {
	HandleFunc(path string, handleFunc func(http.ResponseWriter, *http.Request))
	Listen(address string, port int) error
	ServeStatic(staticDir, pathRoot string)

	SetReadTimeout(timeout *time.Duration)
	SetWriteTimeout(timeout *time.Duration)
	SetIdleTimeout(timeout *time.Duration)

	SetTLSConf(conf *tls.Config)
	SetTLSServing(certFile, keyFile string)

	SetDefaultWrapper(WrapperFunc)
}

type WrapperFunc

type WrapperFunc func(func(http.ResponseWriter, *http.Request) int) func(http.ResponseWriter, *http.Request)

Jump to

Keyboard shortcuts

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