goboots

package module
v0.11.6 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: MIT Imports: 42 Imported by: 0

README

goboots

version 0.11.5

goboots

A Web Framework written in Go.
This is not fully ready for production.

Installation:

run go get -u github.com/gabstv/goboots/goboots

Project Setup

run goboots new path/to/myprojectname (e.g. goboots new github.com/gabstv/mywebsite)

Scaffolding:

  • Create a new controller:
    • Be at your project's base folder
    • Run goboots scaff c MyControllerName

Benchmarks

go test -bench=. -benchmem 2>/dev/null

####v 0.4.0 @ iMac i7 3.4 Ghz (Mid 2011)

Simple	      100000	     13807 ns/op	    2269 B/op	      48 allocs/op
Route15	      100000	     15551 ns/op	    2625 B/op	      49 allocs/op
Route75	      100000	     15147 ns/op	    2483 B/op	      49 allocs/op
Route150	  100000	     14708 ns/op	    2766 B/op	      49 allocs/op
Route300	  100000	     15395 ns/op	    2481 B/op	      49 allocs/op
Route3000	  100000	     15842 ns/op	    2486 B/op	      49 allocs/op
Middleware	  200000	     13529 ns/op	    2418 B/op	      48 allocs/op
Composite	  100000	     13814 ns/op	    2783 B/op	      49 allocs/op

Comparison with popular Go web frameworks

Documentation

Index

Constants

View Source
const (
	ErrNil = 0
	// TLS
	ErrTLSNil = 100
)

Variables

This section is empty.

Functions

func CloseSessionStorage

func CloseSessionStorage()

func CompressFilter

func CompressFilter(in *In) bool

based on https://gist.github.com/the42/1956518

func DeleteItem

func DeleteItem(slice interface{}, i int)

func DestroySession

func DestroySession(w http.ResponseWriter, r *http.Request, s *Session)

func FlushSession

func FlushSession(s *Session) error

func FormatPath

func FormatPath(rawpath string) string

func InsertItem

func InsertItem(slice interface{}, i int, val interface{})

func IntMax

func IntMax(a, b int) int

func LocalizeTemplate

func LocalizeTemplate(templateStr string, langcode string, provider i18n.Provider) string

func NewMockFileInfo added in v0.11.5

func NewMockFileInfo(name string, size int64, mode os.FileMode, modTime time.Time, isDir bool) os.FileInfo

func NoCacheFilter added in v0.11.5

func NoCacheFilter(in *In) bool

func RegisterControllerGlobal added in v0.4.4

func RegisterControllerGlobal(controller IController)

func RegisterSessionStorageDriver

func RegisterSessionStorageDriver(name string, engine ISessionDBEngine)

func ServedByProxyFilter added in v0.11.5

func ServedByProxyFilter(in *In) bool

func SetCookieAdv

func SetCookieAdv(w http.ResponseWriter, name string, value string, path string, domain string, expires time.Time, maxage int, secure bool, httpOnly bool)

func SetCookieSimple

func SetCookieSimple(w http.ResponseWriter, key string, value string)

SetCookieSimple sets an unsafe cookie

func SetUserLang

func SetUserLang(w http.ResponseWriter, r *http.Request, langcode string)

func StrConcat

func StrConcat(strings ...string) string

func StringIndexOf

func StringIndexOf(haystack []string, needle string) int

Types

type ActionDefinition added in v0.3.0

type ActionDefinition struct {
	Host, Method, Url, Action string
	Star                      bool
	Args                      map[string]string
}

func (*ActionDefinition) String added in v0.3.0

func (a *ActionDefinition) String() string

type App

type App struct {
	// public
	AppConfigPath string
	Config        *AppConfig
	Router        *Router
	Filters       []Filter
	StaticFilters []Filter
	ByteCaches    *ByteCacheCollection
	GenericCaches *GenericCacheCollection
	Random        *rand.Rand
	HTTPErrorFunc func(w http.ResponseWriter, r *http.Request, err int)
	GetLangFunc   func(w http.ResponseWriter, r *http.Request) string
	ServeMux      *httprouter.Router

	Monitor           appMonitor
	Logger            Logger
	AccessLogger      Logger
	TemplateProcessor TemplateProcessor
	I18nProvider      i18n.Provider
	// contains filtered or unexported fields
}

func NewApp added in v0.3.0

func NewApp() *App

func (*App) AddRouteLine added in v0.4.4

func (a *App) AddRouteLine(line string) error

func (*App) AddTemplateFunc added in v0.2.1

func (a *App) AddTemplateFunc(key string, tfunc interface{})

func (*App) AddTemplateFuncMap added in v0.2.1

func (a *App) AddTemplateFuncMap(tfmap map[string]interface{})

func (*App) BenchLoadAll added in v0.4.4

func (a *App) BenchLoadAll() error

func (*App) DefaultGetLang added in v0.11.5

func (a *App) DefaultGetLang(w http.ResponseWriter, r *http.Request) string

func (*App) DoHTTPError

func (a *App) DoHTTPError(w http.ResponseWriter, r *http.Request, err int)

func (*App) GetLayout

func (a *App) GetLayout(name string) *template.Template

func (*App) GetLocalizedLayout

func (a *App) GetLocalizedLayout(name string, w http.ResponseWriter, r *http.Request) *template.Template

func (*App) GetLocalizedViewTemplate

func (a *App) GetLocalizedViewTemplate(localpath string, w http.ResponseWriter, r *http.Request) *template.Template

func (*App) GetSession added in v0.3.0

func (app *App) GetSession(w http.ResponseWriter, r *http.Request) *Session

func (*App) GetViewTemplate

func (a *App) GetViewTemplate(localpath string) *template.Template

func (*App) InitSessionStorage

func (app *App) InitSessionStorage(driver string) error

func (*App) Listen

func (app *App) Listen() error

func (*App) LoadConfigFile

func (app *App) LoadConfigFile() error

func (*App) Logvln added in v0.3.0

func (app *App) Logvln(v ...interface{})

func (*App) RegisterController

func (a *App) RegisterController(c IController)

func (*App) ServeFile added in v0.11.5

func (app *App) ServeFile(w http.ResponseWriter, r *http.Request, name string) int

https://golang.org/src/net/http/fs.go?s=18015:18072#L626

func (*App) ServeHTTP

func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

type AppConfig

type AppConfig struct {
	Name            string                    `yaml:"Name"`
	DomainName      string                    `yaml:"DomainName"`
	CookieDomain    string                    `yaml:"CookieDomain"`
	CookiePath      string                    `yaml:"CookiePath"`
	GlobalPageTitle string                    `json:",omitempty"`
	Version         string                    `yaml:"Version"`
	HostAddr        string                    `yaml:"HostAddr"`
	HostAddrTLS     string                    `yaml:"HostAddrTLS"`
	MongoDbs        string                    `yaml:"MongoDbs"`
	Database        string                    `yaml:"Database"`
	Databases       map[string]DatabaseConfig `yaml:"Databases"`
	SessionDb       interface{}               `yaml:"SessionDb"`
	Salt            string                    `yaml:"Salt"`
	LocalePath      string                    `yaml:"LocalePath"`
	DefaultLanguage string                    `yaml:"DefaultLanguage"`
	Data            map[string]string         `yaml:"Data"`

	// TLS
	TLSCertificatePath   string   `yaml:"TLSCertificatePath"`
	TLSKeyPath           string   `yaml:"TLSKeyPath"`
	TLSRedirect          bool     `yaml:"TLSRedirect"`
	TLSRedirectPort      string   `yaml:"TLSRedirectPort"`
	TLSAutocert          bool     `yaml:"TLSAutocert"`
	TLSAutocertWhitelist []string `yaml:"TLSAutocertWhitelist"`
	RawTLSKey            string   `yaml:"RawTLSKey"`
	RawTLSCert           string   `yaml:"RawTLSCert"`

	// Paths
	RoutesConfigPath string   `yaml:"RoutesConfigPath"`
	CachePath        string   `yaml:"CachePath"`
	ViewsFolderPath  string   `yaml:"ViewsFolderPath"`
	ViewsExtensions  []string `yaml:"ViewsExtensions"` // .html, .tpl
	PublicFolderPath string   `yaml:"PublicFolderPath"`

	WatchViewsFolder bool `yaml:"WatchViewsFolder"`

	StaticAccessLog  bool
	DynamicAccessLog bool
	Verbose          bool
	GZipDynamic      bool
	GZipStatic       bool
	SessionDebug     bool `yaml:"SessionDebug"`

	StaticIndexFiles []string `yaml:"StaticIndexFiles"`

	//Gracefully restarts if enabled
	GracefulRestart bool
}

func (*AppConfig) ParseEnv

func (a *AppConfig) ParseEnv()

type AppError

type AppError struct {
	Id      int
	Message string
}

func (*AppError) Error

func (e *AppError) Error() string

type ByteCache

type ByteCache struct {
	Name       string
	Content    []byte
	LastUpdate time.Time
	IsValid    bool
}

type ByteCacheCollection

type ByteCacheCollection struct {
	// contains filtered or unexported fields
}

func NewByteCacheCollection

func NewByteCacheCollection() *ByteCacheCollection

func (*ByteCacheCollection) DeleteCache

func (c *ByteCacheCollection) DeleteCache(name string)

func (*ByteCacheCollection) GetCache

func (c *ByteCacheCollection) GetCache(name string) *ByteCache

func (*ByteCacheCollection) InvalidateCache

func (c *ByteCacheCollection) InvalidateCache(name string)

func (*ByteCacheCollection) IsValid

func (c *ByteCacheCollection) IsValid(name string) bool

func (*ByteCacheCollection) SetCache

func (c *ByteCacheCollection) SetCache(name string, data []byte)

type ConnectionData added in v0.11.5

type ConnectionData struct {
	Id      string
	Path    string
	Request *http.Request
	Started time.Time
}

type Controller

type Controller struct {
	App          *App
	Path         string
	Name         string
	LayoutName   string
	Action       string
	LayoutAction string
	Params       []string
	PageTitle    string
	Layout       string
	ContentType  string
	// contains filtered or unexported fields
}

func (*Controller) GetApp added in v0.11.5

func (c *Controller) GetApp() *App

func (*Controller) GetLayoutName

func (c *Controller) GetLayoutName() string

func (*Controller) GetPageTitle

func (c *Controller) GetPageTitle() string

func (*Controller) Init

func (c *Controller) Init()

func (*Controller) PreFilter

func (c *Controller) PreFilter(in *In) *Out

func (*Controller) SetApp added in v0.3.0

func (c *Controller) SetApp(app *App)

type DatabaseConfig

type DatabaseConfig struct {
	Name       string `yaml:"Name"`
	Connection string `yaml:"Connection"`
	Host       string `yaml:"Host"`
	Database   string `yaml:"Database"`
	User       string `yaml:"User"`
	Password   string `yaml:"Password"`
}

type ErrorPageContent

type ErrorPageContent struct {
	Title        string
	ErrorTitle   string
	ErrorMessage string
	Content      string
}

type Filter

type Filter func(in *In) bool

type GenericCache

type GenericCache struct {
	Name       string
	Content    interface{}
	LastUpdate time.Time
	IsValid    bool
}

type GenericCacheCollection

type GenericCacheCollection struct {
	// contains filtered or unexported fields
}

func NewGenericCacheCollection

func NewGenericCacheCollection() *GenericCacheCollection

func (*GenericCacheCollection) DeleteCache

func (c *GenericCacheCollection) DeleteCache(name string)

func (*GenericCacheCollection) GetCache

func (c *GenericCacheCollection) GetCache(name string) *GenericCache

func (*GenericCacheCollection) InvalidateCache

func (c *GenericCacheCollection) InvalidateCache(name string)

func (*GenericCacheCollection) IsValid

func (c *GenericCacheCollection) IsValid(name string) bool

func (*GenericCacheCollection) SetCache

func (c *GenericCacheCollection) SetCache(name string, data interface{})

type IController

type IController interface {
	GetApp() *App
	SetApp(app *App)
	GetPageTitle() string
	GetLayoutName() string
	Init()
	PreFilter(in *In) *Out
	// contains filtered or unexported methods
}

type ISession

type ISession interface {
	GetData() (string, map[string]interface{}, time.Time)
}

type ISessionDBEngine

type ISessionDBEngine interface {
	SetApp(app *App)
	GetSession(sid string) (*Session, error)
	PutSession(session *Session) error
	NewSession(session *Session) error
	RemoveSession(session *Session) error
	Cleanup(minTime time.Time)
	Close()
}

type In

type In struct {
	R        *http.Request
	W        http.ResponseWriter
	Wsock    *websocket.Conn
	URLParts []string
	Params   Params // set in the new routing method

	Content       *InContent
	LayoutContent *InContent
	App           *App
	Controller    IController
	LangCode      string
	GlobalTitle   string
	// contains filtered or unexported fields
}

func (*In) BeforeOutput added in v0.11.5

func (in *In) BeforeOutput(f InFunc)

func (*In) Continue added in v0.2.0

func (in *In) Continue() *Out

func (*In) Defer added in v0.11.5

func (in *In) Defer(f func())

func (*In) FormFile added in v0.11.5

func (in *In) FormFile(key string) (multipart.File, *multipart.FileHeader, error)

func (*In) FormVal added in v0.3.0

func (in *In) FormVal(key string) string

func (*In) New added in v0.2.0

func (in *In) New() *In

New clones a new In but without the content. Useful to render separate parts

func (*In) OutputBytes added in v0.2.0

func (in *In) OutputBytes(b []byte) *Out

func (*In) OutputContentAsJSON added in v0.11.5

func (in *In) OutputContentAsJSON() *Out

func (*In) OutputFile added in v0.3.0

func (in *In) OutputFile(name string) *Out

func (*In) OutputJSON

func (in *In) OutputJSON(jobj interface{}) *Out

func (*In) OutputLay added in v0.2.0

func (in *In) OutputLay(layout string) *Out

func (*In) OutputLayTpl added in v0.2.0

func (in *In) OutputLayTpl(layout, tplPath string) *Out

func (*In) OutputSoloTpl

func (in *In) OutputSoloTpl(tplPath string) *Out

func (*In) OutputString

func (in *In) OutputString(str string) *Out

func (*In) OutputTpl

func (in *In) OutputTpl(tplPath string) *Out

func (*In) OutputXML

func (in *In) OutputXML(xobj interface{}) *Out

func (*In) ReqBody added in v0.3.0

func (in *In) ReqBody() *InBodyWrapper

func (*In) Session

func (in *In) Session() *Session

func (*In) SetNoCache added in v0.2.1

func (in *In) SetNoCache() *In

func (*In) SprintFormVals added in v0.11.5

func (in *In) SprintFormVals(format string, keys ...string) string

func (*In) T

func (in *In) T(format string, v ...interface{}) string

Translates text to the user language (if available)

func (*In) URLQ added in v0.3.0

func (in *In) URLQ() url.Values

type InBodyWrapper added in v0.3.0

type InBodyWrapper struct {
	R *http.Request
}

func (*InBodyWrapper) UnmarshalJSON added in v0.3.0

func (inbw *InBodyWrapper) UnmarshalJSON(v interface{}) error

func (*InBodyWrapper) UnmarshalXML added in v0.3.0

func (inbw *InBodyWrapper) UnmarshalXML(v interface{}) error

type InContent

type InContent struct {
	// contains filtered or unexported fields
}

func (*InContent) All

func (c *InContent) All() map[string]interface{}

func (*InContent) Del added in v0.11.5

func (c *InContent) Del(key string) *InContent

func (*InContent) Get2

func (c *InContent) Get2(key string) (val interface{}, ok bool)

func (*InContent) GetInt2 added in v0.2.0

func (c *InContent) GetInt2(key string) (val int, ok bool)

func (*InContent) GetString2

func (c *InContent) GetString2(key string) (val string, ok bool)

func (*InContent) Merge

func (c *InContent) Merge(v interface{}) *InContent

func (*InContent) MergeNoOverwrite added in v0.11.5

func (c *InContent) MergeNoOverwrite(v interface{}) *InContent

func (*InContent) Set

func (c *InContent) Set(key string, val interface{}) *InContent

type InFunc added in v0.11.5

type InFunc func(in *In)

type Logger added in v0.3.0

type Logger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Fatalln(v ...interface{})
	Flags() int
	Output(calldepth int, s string) error
	Panic(v ...interface{})
	Panicf(format string, v ...interface{})
	Panicln(v ...interface{})
	Prefix() string
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
	SetFlags(flag int)
	SetPrefix(prefix string)
}

func DefaultLogger added in v0.3.0

func DefaultLogger() Logger

type MockResponseWriter added in v0.11.5

type MockResponseWriter struct {
	// contains filtered or unexported fields
}

func (*MockResponseWriter) Body added in v0.11.5

func (w *MockResponseWriter) Body() []byte

func (*MockResponseWriter) Header added in v0.11.5

func (w *MockResponseWriter) Header() http.Header

func (*MockResponseWriter) StatusCode added in v0.11.5

func (w *MockResponseWriter) StatusCode() int

func (*MockResponseWriter) StringBody added in v0.11.5

func (w *MockResponseWriter) StringBody() string

func (*MockResponseWriter) Write added in v0.11.5

func (w *MockResponseWriter) Write(b []byte) (int, error)

func (*MockResponseWriter) WriteHeader added in v0.11.5

func (w *MockResponseWriter) WriteHeader(status int)

type Out

type Out struct {
	// contains filtered or unexported fields
}

func (*Out) Context added in v0.11.5

func (o *Out) Context() context.Context

func (*Out) IsContinue added in v0.2.0

func (o *Out) IsContinue() bool

func (*Out) Render added in v0.11.5

func (o *Out) Render(w http.ResponseWriter)

func (*Out) String

func (o *Out) String() string

type PageContent

type PageContent struct {
	Title       string
	Content     string
	UserContent string
	HeadInclude string
	FootInclude string
}

type Params added in v0.4.4

type Params map[string]string

type RedirectPageContent

type RedirectPageContent struct {
	Title   string
	Message string
	Path    string
}

type Route

type Route struct {
	Method         string   // e.g. GET
	Path           string   // e.g. /app/:id
	Action         string   // e.g. "Application.ShowApp", "404"
	ControllerName string   // e.g. "Application", ""
	MethodName     string   // e.g. "ShowApp", ""
	FixedParams    []string // e.g. "arg1","arg2","arg3" (CSV formatting)
	TreePath       string   // e.g. "/GET/app/:id"
	TLSOnly        bool
	// contains filtered or unexported fields
}

func NewRoute added in v0.3.0

func NewRoute(method, path, action, fixedArgs, routesPath string, line int, tlsonly bool, app *App) (r *Route)

Prepares the route to be used in matching.

type RouteMatch added in v0.3.0

type RouteMatch struct {
	Action         string // e.g. 404
	ControllerName string // e.g. Application
	MethodName     string // e.g. ShowApp
	FixedParams    []string
	Params         Params // e.g. {id: 123}
	TLSOnly        bool
}

type Router added in v0.3.0

type Router struct {
	Routes []*Route
	Tree   *pathtree.Node
	// contains filtered or unexported fields
}

func NewRouter added in v0.3.0

func NewRouter(app *App, routesPath string) *Router

func (*Router) Refresh added in v0.3.0

func (router *Router) Refresh() (err error)

Refresh re-reads the routes file and re-calculates the routing table. Returns an error if a specified action could not be found.

func (*Router) Reverse added in v0.3.0

func (router *Router) Reverse(action string, argValues map[string]string) *ActionDefinition

func (*Router) Route added in v0.3.0

func (router *Router) Route(req *http.Request) *RouteMatch

type SessFlash

type SessFlash struct {
	// contains filtered or unexported fields
}

func (*SessFlash) All

func (s *SessFlash) All() map[string]interface{}

func (*SessFlash) Clear

func (s *SessFlash) Clear()

func (*SessFlash) Del

func (s *SessFlash) Del(key string)

func (*SessFlash) Get

func (s *SessFlash) Get(key string) interface{}

func (*SessFlash) Get2

func (s *SessFlash) Get2(key string) (interface{}, bool)

func (*SessFlash) Set

func (s *SessFlash) Set(key string, val interface{})

type Session

type Session struct {
	SID     string
	Data    map[string]interface{}
	Flash   SessFlash `json:"-" bson:"-"` // never save flash
	Time    time.Time
	Updated time.Time
	// contains filtered or unexported fields
}

func (*Session) DeleteData added in v0.11.5

func (s *Session) DeleteData(key string)

func (*Session) Expire

func (s *Session) Expire(t time.Time)

func (*Session) Flush

func (s *Session) Flush()

func (*Session) GetBool

func (s *Session) GetBool(key string) (bool, bool)

func (*Session) GetBoolD

func (s *Session) GetBoolD(key string, defaultValue bool) bool

func (*Session) GetData

func (s *Session) GetData() (string, map[string]interface{}, time.Time)

func (*Session) GetExpires added in v0.3.0

func (s *Session) GetExpires() time.Time

func (*Session) GetInt32

func (s *Session) GetInt32(key string) (int, bool)

func (*Session) GetInt32D

func (s *Session) GetInt32D(key string, defaultValue int) int

func (*Session) GetInt64 added in v0.11.5

func (s *Session) GetInt64(key string) (int64, bool)

func (*Session) GetInt64D added in v0.11.5

func (s *Session) GetInt64D(key string, defaultValue int64) int64

func (*Session) GetString

func (s *Session) GetString(key string) (string, bool)

func (*Session) GetStringD

func (s *Session) GetStringD(key string, defaultValue string) string

func (*Session) RequestURI added in v0.11.5

func (s *Session) RequestURI() string

type SessionDevNull added in v0.4.4

type SessionDevNull struct {
	// contains filtered or unexported fields
}

func (*SessionDevNull) Cleanup added in v0.4.4

func (s *SessionDevNull) Cleanup(minTime time.Time)

func (*SessionDevNull) Close added in v0.4.4

func (s *SessionDevNull) Close()

func (*SessionDevNull) GetSession added in v0.4.4

func (s *SessionDevNull) GetSession(sid string) (*Session, error)

func (*SessionDevNull) NewSession added in v0.4.4

func (s *SessionDevNull) NewSession(s2 *Session) error

func (*SessionDevNull) PutSession added in v0.4.4

func (s *SessionDevNull) PutSession(s2 *Session) error

func (*SessionDevNull) RemoveSession added in v0.4.4

func (s *SessionDevNull) RemoveSession(s2 *Session) error

func (*SessionDevNull) SetApp added in v0.4.4

func (s *SessionDevNull) SetApp(app *App)

type TemplateProcessor added in v0.11.5

type TemplateProcessor interface {
	Walk(root string, walkFn filepath.WalkFunc) error
	ReadFile(filename string) ([]byte, error)
}

Directories

Path Synopsis
examples
session-db-drivers
skeleton

Jump to

Keyboard shortcuts

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