engine

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 45 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// DEV is for develop
	DEV = "dev"
	// PROD is for production
	PROD = "prod"
)
View Source
const (
	BeforeStatic = iota
	BeforeRouter
	BeforeExec
	AfterExec
	FinishRouter
)

default filter execution points

Variables

View Source
var (
	// BConfig is the default config for Application
	BConfig *Config
	// AppConfig is the instance of Config, store the config information from file
	AppConfig *bhojpurAppConfig
	// AppPath is the absolute path to the app
	AppPath string
	// GlobalSessions is the instance for the session manager
	GlobalSessions *session.Manager

	// WorkPath is the absolute path to project root directory
	WorkPath string
)
View Source
var (
	// ErrAbort custom error when user stop request handler manually.
	ErrAbort = errors.New("user stop run")
	// GlobalControllerRouter store comments with controller. pkgpath+controller:comments
	GlobalControllerRouter = make(map[string][]ControllerComments)
)
View Source
var ErrorMaps = make(map[string]*errorInfo, 10)

ErrorMaps holds map of http handlers for each error string. there is 10 kinds default error(40x and 50x)

View Source
var FilterMonitorFunc func(string, string, time.Duration, string, int) bool

FilterMonitorFunc is default monitor filter when admin module is enable. if this func returns, admin module records qps for this request by condition of this function logic. usage:

func MyFilterMonitor(method, requestPath string, t time.Duration, pattern string, statusCode int) bool {
 	if method == "POST" {
		return false
 	}
 	if t.Nanoseconds() < 100 {
		return false
 	}
 	if strings.HasPrefix(requestPath, "/bhojpur") {
		return false
 	}
 	return true
}
websvr.FilterMonitorFunc = MyFilterMonitor.

Functions

func AddAPPStartHook

func AddAPPStartHook(hf ...hookfunc)

AddAPPStartHook is used to register the hookfunc The hookfuncs will run in websvr.Run() such as initiating session , starting middleware , building template, starting admin control and so on.

func AddFuncMap

func AddFuncMap(key string, fn interface{}) error

AddFuncMap let user to register a func in the template.

func AddNamespace

func AddNamespace(nl ...*Namespace)

AddNamespace register Namespace into websvr.Handler support multi Namespace

func AddTemplateExt

func AddTemplateExt(ext string)

AddTemplateExt add new extension for template.

func AddViewPath

func AddViewPath(viewPath string) error

AddViewPath adds a new path to the supported view paths. Can later be used by setting a controller ViewPath to this folder will panic if called after websvr.Run()

func AssetsCSS

func AssetsCSS(text string) template.HTML

AssetsCSS returns stylesheet link tag with src string.

func AssetsJs

func AssetsJs(text string) template.HTML

AssetsJs returns script tag with src string.

func BuildTemplate

func BuildTemplate(dir string, files ...string) error

BuildTemplate will build all template files in a directory. it makes Bhojpur.NET Platform can render any template file in view directory.

func Compare

func Compare(a, b interface{}) (equal bool)

Compare is a quick and dirty comparison function. It will convert whatever you give it to strings and see if the two values are equal. Whitespace is trimmed. Used by the template parser as "eq".

func CompareNot

func CompareNot(a, b interface{}) (equal bool)

CompareNot !Compare

func CtrlAny added in v0.0.4

func CtrlAny(rootpath string, f interface{})

CtrlAny see HttpServer.CtrlAny

func CtrlDelete added in v0.0.4

func CtrlDelete(rootpath string, f interface{})

CtrlDelete see HttpServer.CtrlDelete

func CtrlGet added in v0.0.4

func CtrlGet(rootpath string, f interface{})

CtrlGet see HttpServer.CtrlGet

func CtrlHead added in v0.0.4

func CtrlHead(rootpath string, f interface{})

CtrlHead see HttpServer.CtrlHead

func CtrlOptions added in v0.0.4

func CtrlOptions(rootpath string, f interface{})

CtrlOptions see HttpServer.CtrlOptions

func CtrlPatch added in v0.0.4

func CtrlPatch(rootpath string, f interface{})

CtrlPatch see HttpServer.CtrlPatch

func CtrlPost added in v0.0.4

func CtrlPost(rootpath string, f interface{})

CtrlPost see HttpServer.CtrlGet

func CtrlPut added in v0.0.4

func CtrlPut(rootpath string, f interface{})

CtrlPut see HttpServer.CtrlPut

func Date

func Date(t time.Time, format string) string

Date takes a PHP like date func to Go's time format.

func DateFormat

func DateFormat(t time.Time, layout string) (datestring string)

DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"

func DateParse

func DateParse(dateString, format string) (time.Time, error)

DateParse Parse Date use PHP time format.

func ExceptMethodAppend

func ExceptMethodAppend(action string)

ExceptMethodAppend to append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter

func Exception

func Exception(errCode uint64, ctx *context.Context)

Exception Write HttpStatus with errCode and Exec error handler if exist.

func ExecuteTemplate

func ExecuteTemplate(wr io.Writer, name string, data interface{}) error

ExecuteTemplate applies the template with name to the specified data object, writing the output to wr. A template will be executed safely in parallel.

func ExecuteViewPathTemplate

func ExecuteViewPathTemplate(wr io.Writer, name string, viewPath string, data interface{}) error

ExecuteViewPathTemplate applies the template with name and from specific viewPath to the specified data object, writing the output to wr. A template will be executed safely in parallel.

func GetConfig

func GetConfig(returnType, key string, defaultVal interface{}) (value interface{}, err error)

GetConfig get the Appconfig

func HTML2str

func HTML2str(html string) string

HTML2str returns escaping text convert from html.

func HasTemplateExt

func HasTemplateExt(paths string) bool

HasTemplateExt return this path contains supported template extension of Bhojpur.NET Platform or not.

func Htmlquote

func Htmlquote(text string) string

Htmlquote returns quoted html string.

func Htmlunquote

func Htmlunquote(text string) string

Htmlunquote returns unquoted html string.

func InitBhojpurBeforeTest added in v0.0.4

func InitBhojpurBeforeTest(appConfigPath string)

InitBhojpurBeforeTest is for test package init

func LoadAppConfig

func LoadAppConfig(adapterName, configPath string) error

LoadAppConfig allow developer to apply a config file

func LogAccess

func LogAccess(ctx *ctxsvr.Context, startTime *time.Time, statusCode int)

LogAccess logging info HTTP Access

func MapGet

func MapGet(arg1 interface{}, arg2 ...interface{}) (interface{}, error)

MapGet getting value from map by keys usage:

Data["m"] = M{
    "a": 1,
    "1": map[string]float64{
        "c": 4,
    },
}

{{ map_get m "a" }} // return 1 {{ map_get m 1 "c" }} // return 4

func NotNil

func NotNil(a interface{}) (isNil bool)

NotNil the same as CompareNot

func ParseForm

func ParseForm(form url.Values, obj interface{}) error

ParseForm will parse form values to struct via tag.

func Policy

func Policy(pattern, method string, policy ...PolicyFunc)

Policy Register new policy in Bhojpur Web

func RenderForm

func RenderForm(obj interface{}) template.HTML

RenderForm will render object to form html. obj must be a struct pointer. nolint

func Run

func Run(params ...string)

Run the Bhojpur.NET Platform's primary web server engine. websvr.Run() default run on HttpPort websvr.Run("localhost") websvr.Run(":8089") websvr.Run("127.0.0.1:8089")

func RunWithMiddleWares

func RunWithMiddleWares(addr string, mws ...MiddleWare)

RunWithMiddleWares Run the Bhojpur.NET Platform primary web server engine with middlewares.

func SetTemplateFSFunc

func SetTemplateFSFunc(fnt templateFSFunc)

SetTemplateFSFunc set default filesystem function

func Str2html

func Str2html(raw string) template.HTML

Str2html Convert string to template.HTML type.

func Substr

func Substr(s string, start, length int) string

Substr returns the substr from start to length.

func TestBhojpurInit added in v0.0.4

func TestBhojpurInit(ap string)

TestBhojpurInit is for test package init

func URLFor

func URLFor(endpoint string, values ...interface{}) string

URLFor returns url string with another registered controller handler with params.

	usage:

	URLFor(".index")
	print URLFor("index")
 router /login
	print URLFor("login")
	print URLFor("login", "next","/"")
 router /profile/:username
	print UrlFor("profile", ":username","John Doe")
	result:
	/
	/login
	/login?next=/
	/user/John%20Doe

func Walk

func Walk(fs http.FileSystem, root string, walkFn filepath.WalkFunc) error

Walk walks the file tree rooted at root in filesystem, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn.

Types

type Config

type Config struct {
	// AppName
	// @Description Application's name. You'd better set it because we use it to do some logging and tracing
	// @Default bhojpur
	AppName string // Application name
	// RunMode
	// @Description it's the same as environment. In general, we have different run modes.
	// For example, the most common case is using dev, test, prod three environments
	// when you are developing the web application, you should set it as dev
	// when you completed coding and want QA to test your code, you should deploy your application
	// to test environment and the RunMode should be set as test
	// when you completed all tests, you want to deploy it to prod, you should set it to prod
	// You should never set RunMode="dev" when you deploy the application to prod
	// because Bhojpur Web will do more things which need Go SDK and other tools when it found out the RunMode="dev"
	// @Default dev
	RunMode string // Running Mode: dev | prod

	// RouterCaseSensitive
	// @Description If it was true, it means that the router is case sensitive.
	// For example, when you register a router with pattern "/hello",
	// 1. If this is true, and the request URL is "/Hello", it won't match this pattern
	// 2. If this is false and the request URL is "/Hello", it will match this pattern
	// @Default true
	RouterCaseSensitive bool
	// RecoverPanic
	// @Description if it was true, Bhojpur Web will try to recover from panic when it serves your http request
	// So you should notice that it doesn't mean that Bhojpur Web will recover all panic cases.
	// @Default true
	RecoverPanic bool
	// CopyRequestBody
	// @Description if it's true, Bhojpur Web will copy the request body. But if the request body's size > MaxMemory,
	// Bhojpur Web will return 413 as http status
	// If you are building RESTful API, please set it to true.
	// And, if you want to read data from request Body multiple times, please set it to true
	// In general, if you don't meet any performance issue, you could set it to true
	// @Default false
	CopyRequestBody bool
	// EnableGzip
	// @Description If it was true, Bhojpur Web will try to compress data by using zip algorithm.
	// But there are two points:
	// 1. Only static resources will be compressed
	// 2. Only those static resource which has the extension specified by StaticExtensionsToGzip will be compressed
	// @Default false
	EnableGzip bool
	// EnableErrorsShow
	// @Description If it's true, Bhojpur Web will show error message to page
	// it will work with ErrorMaps which allows you register some error handler
	// You may want to set it to false when application was deploy to prod environment
	// because you may not want to expose your internal error msg to your users
	// it's a little bit unsafe
	// @Default true
	EnableErrorsShow bool
	// EnableErrorsRender
	// @Description If it's true, it will output the error msg as a page. It's similar to EnableErrorsShow
	// And this configure item only work in dev run mode (see RunMode)
	// @Default true
	EnableErrorsRender bool
	// ServerName
	// @Description server name. For example, in large scale system,
	// you may want to deploy your application to several machines, so that each of them has a server name
	// we suggest you'd better set value because Bhojpur Web use this to output some DEBUG msg,
	// or integrated with other tools such as tracing, metrics
	// @Default
	ServerName string

	// RecoverFunc
	// @Description when Bhojpur Web want to recover from panic, it will use this func as callback
	// see RecoverPanic
	// @Default defaultRecoverPanic
	RecoverFunc func(*context.Context, *Config)
	// @Description MaxMemory and MaxUploadSize are used to limit the request body
	// if the request is not uploading file, MaxMemory is the max size of request body
	// if the request is uploading file, MaxUploadSize is the max size of request body
	// if CopyRequestBody is true, this value will be used as the threshold of request body
	// see CopyRequestBody
	// the default value is 1 << 26 (64MB)
	// @Default 67108864
	MaxMemory int64
	// MaxUploadSize
	// @Description  MaxMemory and MaxUploadSize are used to limit the request body
	// if the request is not uploading file, MaxMemory is the max size of request body
	// if the request is uploading file, MaxUploadSize is the max size of request body
	// the default value is 1 << 30 (1GB)
	// @Default 1073741824
	MaxUploadSize int64
	// Listen
	// @Description the configuration about socket or http protocol
	Listen Listen
	// WebConfig
	// @Description the configuration about Web
	WebConfig WebConfig
	// LogConfig
	// @Description log configuration
	Log LogConfig
}

Config is the main struct for BConfig TODO after supporting multiple servers, remove common config to somewhere else

type Controller

type Controller struct {
	// context data
	Ctx  *ctxsvr.Context
	Data map[interface{}]interface{}

	AppController interface{}

	// template data
	TplName        string
	ViewPath       string
	Layout         string
	LayoutSections map[string]string // the key is the section name and the value is the template name
	TplPrefix      string
	TplExt         string
	EnableRender   bool

	// xsrf data
	EnableXSRF bool

	XSRFExpire int

	// session
	CruSession session.Store
	// contains filtered or unexported fields
}

Controller defines some basic http request handler operations, such as http context, template and view, session and xsrf.

func (*Controller) Abort

func (c *Controller) Abort(code string)

Abort stops controller handler and show the error data if code is defined in ErrorMap or code string.

func (*Controller) Bind added in v0.0.4

func (c *Controller) Bind(obj interface{}) error

Bind if the content type is form, we read data from form otherwise, read data from request body

func (*Controller) BindForm added in v0.0.4

func (c *Controller) BindForm(obj interface{}) error

BindForm read data from form

func (*Controller) BindJSON added in v0.0.4

func (c *Controller) BindJSON(obj interface{}) error

BindJSON only read data from http request body

func (*Controller) BindProtobuf added in v0.0.4

func (c *Controller) BindProtobuf(obj proto.Message) error

BindProtobuf only read data from http request body

func (*Controller) BindXML added in v0.0.4

func (c *Controller) BindXML(obj interface{}) error

BindXML only read data from http request body

func (*Controller) BindYAML added in v0.0.4

func (c *Controller) BindYAML(obj interface{}) error

BindYAML only read data from http request body

func (*Controller) CheckXSRFCookie

func (c *Controller) CheckXSRFCookie() bool

CheckXSRFCookie checks xsrf token in this request is valid or not. the token can provided in request header "X-Xsrftoken" and "X-CsrfToken" or in form field value named as "_xsrf".

func (*Controller) CustomAbort

func (c *Controller) CustomAbort(status int, body string)

CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.

func (*Controller) DelSession

func (c *Controller) DelSession(name interface{}) error

DelSession removes value from session.

func (*Controller) Delete

func (c *Controller) Delete()

Delete adds a request function to handle DELETE request.

func (*Controller) DestroySession

func (c *Controller) DestroySession() error

DestroySession cleans session data and session cookie.

func (*Controller) Finish

func (c *Controller) Finish()

Finish runs after request function execution.

func (*Controller) Get

func (c *Controller) Get()

Get adds a request function to handle GET request.

func (*Controller) GetBool

func (c *Controller) GetBool(key string, def ...bool) (bool, error)

GetBool returns input value as bool or the default value while it's present and input is blank.

func (*Controller) GetControllerAndAction

func (c *Controller) GetControllerAndAction() (string, string)

GetControllerAndAction gets the executing controller name and action name.

func (*Controller) GetFile

func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, error)

GetFile returns the file data in file upload field named as key. it returns the first one of multi-uploaded files.

func (*Controller) GetFiles

func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error)

GetFiles return multi-upload files files, err:=c.GetFiles("myfiles")

if err != nil {
	http.Error(w, err.Error(), http.StatusNoContent)
	return
}
for i, _ := range files {
	//for each fileheader, get a handle to the actual file
	file, err := files[i].Open()
	defer file.Close()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	//create destination file making sure the path is writeable.
	dst, err := os.Create("upload/" + files[i].Filename)
	defer dst.Close()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	//copy the uploaded file to the destination file
	if _, err := io.Copy(dst, file); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}

func (*Controller) GetFloat

func (c *Controller) GetFloat(key string, def ...float64) (float64, error)

GetFloat returns input value as float64 or the default value while it's present and input is blank.

func (*Controller) GetInt

func (c *Controller) GetInt(key string, def ...int) (int, error)

GetInt returns input as an int or the default value while it's present and input is blank

func (*Controller) GetInt16

func (c *Controller) GetInt16(key string, def ...int16) (int16, error)

GetInt16 returns input as an int16 or the default value while it's present and input is blank

func (*Controller) GetInt32

func (c *Controller) GetInt32(key string, def ...int32) (int32, error)

GetInt32 returns input as an int32 or the default value while it's present and input is blank

func (*Controller) GetInt64

func (c *Controller) GetInt64(key string, def ...int64) (int64, error)

GetInt64 returns input value as int64 or the default value while it's present and input is blank.

func (*Controller) GetInt8

func (c *Controller) GetInt8(key string, def ...int8) (int8, error)

GetInt8 return input as an int8 or the default value while it's present and input is blank

func (*Controller) GetSecureCookie

func (c *Controller) GetSecureCookie(Secret, key string) (string, bool)

GetSecureCookie returns decoded cookie value from encoded browser cookie values.

func (*Controller) GetSession

func (c *Controller) GetSession(name interface{}) interface{}

GetSession gets value from session.

func (*Controller) GetString

func (c *Controller) GetString(key string, def ...string) string

GetString returns the input value by key string or the default value while it's present and input is blank

func (*Controller) GetStrings

func (c *Controller) GetStrings(key string, def ...[]string) []string

GetStrings returns the input string slice by key string or the default value while it's present and input is blank it's designed for multi-value input field such as checkbox(input[type=checkbox]), multi-selection.

func (*Controller) GetUint16

func (c *Controller) GetUint16(key string, def ...uint16) (uint16, error)

GetUint16 returns input as an uint16 or the default value while it's present and input is blank

func (*Controller) GetUint32

func (c *Controller) GetUint32(key string, def ...uint32) (uint32, error)

GetUint32 returns input as an uint32 or the default value while it's present and input is blank

func (*Controller) GetUint64

func (c *Controller) GetUint64(key string, def ...uint64) (uint64, error)

GetUint64 returns input value as uint64 or the default value while it's present and input is blank.

func (*Controller) GetUint8

func (c *Controller) GetUint8(key string, def ...uint8) (uint8, error)

GetUint8 return input as an uint8 or the default value while it's present and input is blank

func (*Controller) HandlerFunc

func (c *Controller) HandlerFunc(fnname string) bool

HandlerFunc call function with the name

func (*Controller) Head

func (c *Controller) Head()

Head adds a request function to handle HEAD request.

func (*Controller) Init

func (c *Controller) Init(ctx *ctxsvr.Context, controllerName, actionName string, app interface{})

Init generates default values of controller operations.

func (*Controller) Input

func (c *Controller) Input() (url.Values, error)

Input returns the input data map from POST or PUT request body and query string.

func (*Controller) IsAjax

func (c *Controller) IsAjax() bool

IsAjax returns this request is ajax or not.

func (*Controller) JSONResp added in v0.0.4

func (c *Controller) JSONResp(data interface{}) error

func (*Controller) Mapping

func (c *Controller) Mapping(method string, fn func())

Mapping the method to function

func (*Controller) Options

func (c *Controller) Options()

Options adds a request function to handle OPTIONS request.

func (*Controller) ParseForm

func (c *Controller) ParseForm(obj interface{}) error

ParseForm maps input data map to obj struct.

func (*Controller) Patch

func (c *Controller) Patch()

Patch adds a request function to handle PATCH request.

func (*Controller) Post

func (c *Controller) Post()

Post adds a request function to handle POST request.

func (*Controller) Prepare

func (c *Controller) Prepare()

Prepare runs after Init before request function execution.

func (*Controller) Put

func (c *Controller) Put()

Put adds a request function to handle PUT request.

func (*Controller) Redirect

func (c *Controller) Redirect(url string, code int)

Redirect sends the redirection response to url with status code.

func (*Controller) Render

func (c *Controller) Render() error

Render sends the response with rendered template bytes as text/html type.

func (*Controller) RenderBytes

func (c *Controller) RenderBytes() ([]byte, error)

RenderBytes returns the bytes of rendered template string. Do not send out response.

func (*Controller) RenderString

func (c *Controller) RenderString() (string, error)

RenderString returns the rendered template string. Do not send out response.

func (*Controller) Resp added in v0.0.4

func (c *Controller) Resp(data interface{}) error

Resp sends response based on the Accept Header By default response will be in JSON it's different from ServeXXX methods because we don't store the data to Data field

func (*Controller) SaveToFile

func (c *Controller) SaveToFile(fromFile, toFile string) error

SaveToFile saves uploaded file to new path. it only operates the first one of mutil-upload form file field.

func (*Controller) SaveToFileWithBuffer added in v0.0.4

func (c *Controller) SaveToFileWithBuffer(fromFile string, toFile string, buf []byte) error

func (*Controller) ServeFormatted

func (c *Controller) ServeFormatted(encoding ...bool) error

ServeFormatted serve YAML, XML OR JSON, depending on the value of the Accept header

func (*Controller) ServeJSON

func (c *Controller) ServeJSON(encoding ...bool) error

ServeJSON sends a json response with encoding charset.

func (*Controller) ServeJSONP

func (c *Controller) ServeJSONP() error

ServeJSONP sends a jsonp response.

func (*Controller) ServeXML

func (c *Controller) ServeXML() error

ServeXML sends xml response.

func (*Controller) ServeYAML

func (c *Controller) ServeYAML() error

ServeYAML sends yaml response.

func (*Controller) SessionRegenerateID

func (c *Controller) SessionRegenerateID() error

SessionRegenerateID regenerates session id for this session. the session data have no changes.

func (*Controller) SetData

func (c *Controller) SetData(data interface{})

SetData set the data depending on the accepted

func (*Controller) SetSecureCookie

func (c *Controller) SetSecureCookie(Secret, name, value string, others ...interface{})

SetSecureCookie puts value into cookie after encoded the value.

func (*Controller) SetSession

func (c *Controller) SetSession(name interface{}, value interface{}) error

SetSession puts value into session.

func (*Controller) StartSession

func (c *Controller) StartSession() session.Store

StartSession starts session and load old session data info this controller.

func (*Controller) StopRun

func (c *Controller) StopRun()

StopRun makes panic of USERSTOPRUN error and go to recover function if defined.

func (*Controller) Trace

func (c *Controller) Trace()

Trace adds a request function to handle Trace request. this method SHOULD NOT be overridden. https://tools.ietf.org/html/rfc7231#section-4.3.8 The TRACE method requests a remote, application-level loop-back of the request message. The final recipient of the request SHOULD reflect the message received, excluding some fields described below, back to the client as the message body of a 200 (OK) response with a Content-Type of "message/http" (Section 8.3.1 of [RFC7230]).

func (*Controller) URLFor

func (c *Controller) URLFor(endpoint string, values ...interface{}) string

URLFor does another controller handler in this request function. it goes to this controller method if endpoint is not clear.

func (*Controller) URLMapping

func (c *Controller) URLMapping()

URLMapping register the internal Controller router.

func (*Controller) XMLResp added in v0.0.4

func (c *Controller) XMLResp(data interface{}) error

func (*Controller) XSRFFormHTML

func (c *Controller) XSRFFormHTML() string

XSRFFormHTML writes an input field contains xsrf token value.

func (*Controller) XSRFToken

func (c *Controller) XSRFToken() string

XSRFToken creates a CSRF token string and returns.

func (*Controller) YamlResp added in v0.0.4

func (c *Controller) YamlResp(data interface{}) error

type ControllerComments

type ControllerComments struct {
	Method           string
	Router           string
	Filters          []*ControllerFilter
	ImportComments   []*ControllerImportComments
	FilterComments   []*ControllerFilterComments
	AllowHTTPMethods []string
	Params           []map[string]string
	MethodParams     []*param.MethodParam
}

ControllerComments store the comment for the controller method

type ControllerCommentsSlice

type ControllerCommentsSlice []ControllerComments

ControllerCommentsSlice implements the sort interface

func (ControllerCommentsSlice) Len

func (p ControllerCommentsSlice) Len() int

func (ControllerCommentsSlice) Less

func (p ControllerCommentsSlice) Less(i, j int) bool

func (ControllerCommentsSlice) Swap

func (p ControllerCommentsSlice) Swap(i, j int)

type ControllerFilter

type ControllerFilter struct {
	Pattern        string
	Pos            int
	Filter         FilterFunc
	ReturnOnOutput bool
	ResetParams    bool
}

ControllerFilter store the filter for controller

type ControllerFilterComments

type ControllerFilterComments struct {
	Pattern        string
	Pos            int
	Filter         string // NOQA
	ReturnOnOutput bool
	ResetParams    bool
}

ControllerFilterComments store the comment for controller level filter

type ControllerImportComments

type ControllerImportComments struct {
	ImportPath  string
	ImportAlias string
}

ControllerImportComments store the import comment for controller needed

type ControllerInfo

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

ControllerInfo holds information about the controller.

func (*ControllerInfo) GetPattern

func (c *ControllerInfo) GetPattern() string

type ControllerInterface

type ControllerInterface interface {
	Init(ct *ctxsvr.Context, controllerName, actionName string, app interface{})
	Prepare()
	Get()
	Post()
	Delete()
	Put()
	Head()
	Patch()
	Options()
	Trace()
	Finish()
	Render() error
	XSRFToken() string
	CheckXSRFCookie() bool
	HandlerFunc(fn string) bool
	URLMapping()
}

ControllerInterface is an interface to uniform all controller handler.

type ControllerOption added in v0.0.4

type ControllerOption func(*ControllerInfo)

func WithRouterMethods added in v0.0.4

func WithRouterMethods(ctrlInterface ControllerInterface, mappingMethod ...string) ControllerOption

func WithRouterSessionOn added in v0.0.4

func WithRouterSessionOn(sessionOn bool) ControllerOption

type ControllerRegister

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

ControllerRegister containers registered router rules, controller handlers and filters.

func NewControllerRegister

func NewControllerRegister() *ControllerRegister

NewControllerRegister returns a new ControllerRegister. Usually you should not use this method please use NewControllerRegisterWithCfg

func NewControllerRegisterWithCfg

func NewControllerRegisterWithCfg(cfg *Config) *ControllerRegister

func (*ControllerRegister) Add

func (p *ControllerRegister) Add(pattern string, c ControllerInterface, opts ...ControllerOption)

Add controller handler and pattern rules to ControllerRegister. usage:

default methods is the same name as method
Add("/user",&UserController{})
Add("/api/list",&RestController{},"*:ListFood")
Add("/api/create",&RestController{},"post:CreateFood")
Add("/api/update",&RestController{},"put:UpdateFood")
Add("/api/delete",&RestController{},"delete:DeleteFood")
Add("/api",&RestController{},"get,post:ApiFunc"
Add("/simple",&SimpleController{},"get:GetFunc;post:PostFunc")

func (*ControllerRegister) AddAuto

AddAuto router to ControllerRegister. example websvr.AddAuto(&MainController{}), MainController has method List and Page. visit the url /main/list to execute List function /main/page to execute Page function.

func (*ControllerRegister) AddAutoPrefix

func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface)

AddAutoPrefix Add auto router to ControllerRegister with prefix. example websvr.AddAutoPrefix("/admin",&MainController{}), MainController has method List and Page. visit the url /admin/main/list to execute List function /admin/main/page to execute Page function.

func (*ControllerRegister) AddMethod

func (p *ControllerRegister) AddMethod(method, pattern string, f HandleFunc)

AddMethod add http method router usage:

AddMethod("get","/api/:id", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) AddRouterMethod added in v0.0.4

func (p *ControllerRegister) AddRouterMethod(httpMethod, pattern string, f interface{})

AddRouterMethod add http method router usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   AddRouterMethod("get","/api/:id", MyController.Ping)

func (*ControllerRegister) Any

func (p *ControllerRegister) Any(pattern string, f HandleFunc)

Any add all method usage:

Any("/api/:id", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) CtrlAny added in v0.0.4

func (p *ControllerRegister) CtrlAny(pattern string, f interface{})

CtrlAny add all method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlAny("/api/:id", MyController.Ping)

func (*ControllerRegister) CtrlDelete added in v0.0.4

func (p *ControllerRegister) CtrlDelete(pattern string, f interface{})

CtrlDelete add delete method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlDelete("/api/:id", MyController.Ping)

func (*ControllerRegister) CtrlGet added in v0.0.4

func (p *ControllerRegister) CtrlGet(pattern string, f interface{})

CtrlGet add get method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlGet("/api/:id", MyController.Ping)

If the receiver of function Ping is pointer, you should use CtrlGet("/api/:id", (*MyController).Ping)

func (*ControllerRegister) CtrlHead added in v0.0.4

func (p *ControllerRegister) CtrlHead(pattern string, f interface{})

CtrlHead add head method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlHead("/api/:id", MyController.Ping)

If the receiver of function Ping is pointer, you should use CtrlHead("/api/:id", (*MyController).Ping)

func (*ControllerRegister) CtrlOptions added in v0.0.4

func (p *ControllerRegister) CtrlOptions(pattern string, f interface{})

CtrlOptions add options method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlOptions("/api/:id", MyController.Ping)

func (*ControllerRegister) CtrlPatch added in v0.0.4

func (p *ControllerRegister) CtrlPatch(pattern string, f interface{})

CtrlPatch add patch method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlPatch("/api/:id", MyController.Ping)

func (*ControllerRegister) CtrlPost added in v0.0.4

func (p *ControllerRegister) CtrlPost(pattern string, f interface{})

CtrlPost add post method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlPost("/api/:id", MyController.Ping)

If the receiver of function Ping is pointer, you should use CtrlPost("/api/:id", (*MyController).Ping)

func (*ControllerRegister) CtrlPut added in v0.0.4

func (p *ControllerRegister) CtrlPut(pattern string, f interface{})

func (*ControllerRegister) Delete

func (p *ControllerRegister) Delete(pattern string, f HandleFunc)

Delete add delete method usage:

Delete("/api/:id", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) FindPolicy

func (p *ControllerRegister) FindPolicy(cont *context.Context) []PolicyFunc

FindPolicy Find Router info for URL

func (*ControllerRegister) FindRouter

func (p *ControllerRegister) FindRouter(context *ctxsvr.Context) (routerInfo *ControllerInfo, isFind bool)

FindRouter Find Router info for URL

func (*ControllerRegister) Get

func (p *ControllerRegister) Get(pattern string, f HandleFunc)

Get add get method usage:

Get("/", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) GetContext

func (p *ControllerRegister) GetContext() *ctxsvr.Context

GetContext returns a context from pool, so usually you should remember to call Reset function to clean the context And don't forget to give back context to pool example:

ctx := p.GetContext()
ctx.Reset(w, q)
defer p.GiveBackContext(ctx)

func (*ControllerRegister) GiveBackContext

func (p *ControllerRegister) GiveBackContext(ctx *ctxsvr.Context)

GiveBackContext put the ctx into pool so that it could be reuse

func (*ControllerRegister) Handler

func (p *ControllerRegister) Handler(pattern string, h http.Handler, options ...interface{})

Handler add user defined Handler

func (*ControllerRegister) Head

func (p *ControllerRegister) Head(pattern string, f HandleFunc)

Head add head method usage:

Head("/api/:id", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) Include

func (p *ControllerRegister) Include(cList ...ControllerInterface)

Include only when the Runmode is dev will generate router file in the router/auto.go from the controller Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})

func (*ControllerRegister) Init added in v0.0.4

func (p *ControllerRegister) Init()

Init will be executed when HttpServer start running

func (*ControllerRegister) InsertFilter

func (p *ControllerRegister) InsertFilter(pattern string, pos int, filter FilterFunc, opts ...FilterOpt) error

InsertFilter Add a FilterFunc with pattern rule and action constant. params is for:

  1. setting the returnOnOutput value (false allows multiple filters to execute)
  2. determining whether or not params need to be reset.

func (*ControllerRegister) InsertFilterChain

func (p *ControllerRegister) InsertFilterChain(pattern string, chain FilterChain, opts ...FilterOpt)

InsertFilterChain is similar to InsertFilter, but it will using chainRoot.filterFunc as input to build a new filterFunc for example, assume that chainRoot is funcA and we add new FilterChain

fc := func(next) {
    return func(ctx) {
          // do something
          next(ctx)
          // do something
    }
}

func (*ControllerRegister) Options

func (p *ControllerRegister) Options(pattern string, f HandleFunc)

Options add options method usage:

Options("/api/:id", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) Patch

func (p *ControllerRegister) Patch(pattern string, f HandleFunc)

Patch add patch method usage:

Patch("/api/:id", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) Post

func (p *ControllerRegister) Post(pattern string, f HandleFunc)

Post add post method usage:

Post("/api", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) Put

func (p *ControllerRegister) Put(pattern string, f HandleFunc)

Put add put method usage:

Put("/api/:id", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*ControllerRegister) ServeHTTP

func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)

Implement http.Handler interface.

func (*ControllerRegister) URLFor

func (p *ControllerRegister) URLFor(endpoint string, values ...interface{}) string

URLFor does another controller handler in this request function. it can access any controller method.

type FileSystem

type FileSystem struct{}

func (FileSystem) Open

func (d FileSystem) Open(name string) (http.File, error)

type FilterChain

type FilterChain func(next FilterFunc) FilterFunc

FilterChain is different from pure FilterFunc when you use this, you must invoke next(ctx) inside the FilterFunc which is returned And all those FilterChain will be invoked before other FilterFunc

type FilterFunc

type FilterFunc = HandleFunc

FilterFunc defines a filter function which is invoked before the controller handler is executed. It's a alias of HandleFunc In fact, the HandleFunc is the last Filter. This is the truth

type FilterHandler

type FilterHandler interface {
	Filter(*ctxsvr.Context) bool
}

FilterHandler is an interface for

var (
	// HTTPMETHOD list the supported http methods.
	HTTPMETHOD = map[string]bool{
		"GET":       true,
		"POST":      true,
		"PUT":       true,
		"DELETE":    true,
		"PATCH":     true,
		"OPTIONS":   true,
		"HEAD":      true,
		"TRACE":     true,
		"CONNECT":   true,
		"MKCOL":     true,
		"COPY":      true,
		"MOVE":      true,
		"PROPFIND":  true,
		"PROPPATCH": true,
		"LOCK":      true,
		"UNLOCK":    true,
	}

	// DefaultAccessLogFilter will skip the accesslog if return true
	DefaultAccessLogFilter FilterHandler = &logFilter{}
)

type FilterOpt

type FilterOpt func(opts *filterOpts)

func WithCaseSensitive

func WithCaseSensitive(sensitive bool) FilterOpt

func WithResetParams

func WithResetParams(reset bool) FilterOpt

func WithReturnOnOutput

func WithReturnOnOutput(ret bool) FilterOpt

type FilterRouter

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

FilterRouter defines a filter operation which is invoked before the controller handler is executed. It can match the URL against a pattern, and execute a filter function when a request with a matching URL arrives.

func (*FilterRouter) ValidRouter

func (f *FilterRouter) ValidRouter(url string, ctx *context.Context) bool

ValidRouter checks if the current request is matched by this filter. If the request is matched, the values of the URL parameters defined by the filter pattern are also returned.

type FlashData

type FlashData struct {
	Data map[string]string
}

FlashData is a tools to maintain data when using across request.

func NewFlash

func NewFlash() *FlashData

NewFlash return a new empty FlashData struct.

func ReadFromRequest

func ReadFromRequest(c *Controller) *FlashData

ReadFromRequest parsed flash data from encoded values in cookie.

func (*FlashData) Error

func (fd *FlashData) Error(msg string, args ...interface{})

Error writes error message to flash.

func (*FlashData) Notice

func (fd *FlashData) Notice(msg string, args ...interface{})

Notice writes notice message to flash.

func (*FlashData) Set

func (fd *FlashData) Set(key string, msg string, args ...interface{})

Set message to flash

func (*FlashData) Store

func (fd *FlashData) Store(c *Controller)

Store does the saving operation of flash data. the data are encoded and saved in cookie.

func (*FlashData) Success

func (fd *FlashData) Success(msg string, args ...interface{})

Success writes success message to flash.

func (*FlashData) Warning

func (fd *FlashData) Warning(msg string, args ...interface{})

Warning writes warning message to flash.

type HandleFunc added in v0.0.4

type HandleFunc func(ctx *ctxsvr.Context)

HandleFunc define how to process the request

type HttpServer

type HttpServer struct {
	Handlers *ControllerRegister
	Server   *http.Server
	Cfg      *Config
}

HttpServer defines Bhojpur.NET Platform application with a new PatternServeMux.

var BhojpurApp *HttpServer

BhojpurApp is an application instance If you are using single server, you could use this But if you need multiple servers, do not use this

func AddTemplateEngine

func AddTemplateEngine(extension string, fn templatePreProcessor) *HttpServer

AddTemplateEngine add a new templatePreProcessor which support extension

func Any

func Any(rootpath string, f HandleFunc) *HttpServer

Any see HttpServer.Any

func AutoPrefix

func AutoPrefix(prefix string, c ControllerInterface) *HttpServer

AutoPrefix see HttpServer.AutoPrefix

func AutoRouter

func AutoRouter(c ControllerInterface) *HttpServer

AutoRouter see HttpServer.AutoRouter

func DelStaticPath

func DelStaticPath(url string) *HttpServer

DelStaticPath removes the static folder setting in this url pattern in Bhojpur.NET Platform application.

func Delete

func Delete(rootpath string, f HandleFunc) *HttpServer

Delete see HttpServer.Delete

func ErrorController

func ErrorController(c ControllerInterface) *HttpServer

ErrorController registers ControllerInterface to each http err code string. usage:

websvr.ErrorController(&controllers.ErrorController{})

func ErrorHandler

func ErrorHandler(code string, h http.HandlerFunc) *HttpServer

ErrorHandler registers http.HandlerFunc to each http err code string. usage:

websvr.ErrorHandler("404",NotFound)
websvr.ErrorHandler("500",InternalServerError)

func Get

func Get(rootpath string, f HandleFunc) *HttpServer

Get see HttpServer.Get

func Handler

func Handler(rootpath string, h http.Handler, options ...interface{}) *HttpServer

Handler see HttpServer.Handler

func Head(rootpath string, f HandleFunc) *HttpServer

Head see HttpServer.Head

func Include

func Include(cList ...ControllerInterface) *HttpServer

Include see HttpServer.Include

func InsertFilter

func InsertFilter(pattern string, pos int, filter FilterFunc, opts ...FilterOpt) *HttpServer

InserFilter see HttpServer.InsertFilter

func InsertFilterChain

func InsertFilterChain(pattern string, filterChain FilterChain, opts ...FilterOpt) *HttpServer

InsertFilterChain see HttpServer.InsertFilterChain

func NewHttpServerWithCfg

func NewHttpServerWithCfg(cfg *Config) *HttpServer

NewHttpServerWithCfg will create an sever with specific cfg

func NewHttpSever

func NewHttpSever() *HttpServer

NewHttpSever returns a new Bhojpur.NET Platform application. this method will use the BConfig as the configure to create HttpServer Be careful that when you update BConfig, the server's Cfg will be updated too

func Options

func Options(rootpath string, f HandleFunc) *HttpServer

Options see HttpServer.Options

func Patch

func Patch(rootpath string, f HandleFunc) *HttpServer

Patch see HttpServer.Patch

func Post

func Post(rootpath string, f HandleFunc) *HttpServer

Post see HttpServer.Post

func Put

func Put(rootpath string, f HandleFunc) *HttpServer

Put see HttpServer.Put

func RESTRouter

func RESTRouter(rootpath string, c ControllerInterface) *HttpServer

RESTRouter see HttpServer.RESTRouter

func Router

func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *HttpServer

Router see HttpServer.Router

func RouterWithOpts added in v0.0.4

func RouterWithOpts(rootpath string, c ControllerInterface, opts ...ControllerOption) *HttpServer

func SetStaticPath

func SetStaticPath(url string, path string) *HttpServer

SetStaticPath sets static directory path and proper url pattern in Bhojpur.NET Platform application. if websvr.SetStaticPath("static","public"), visit /static/* to load static file in folder "public".

func SetViewsPath

func SetViewsPath(path string) *HttpServer

SetViewsPath sets view directory path in Bhojpur.NET Platform application.

func UnregisterFixedRoute

func UnregisterFixedRoute(fixedRoute string, method string) *HttpServer

UnregisterFixedRoute see HttpServer.UnregisterFixedRoute

func (*HttpServer) Any

func (app *HttpServer) Any(rootpath string, f HandleFunc) *HttpServer

Any used to register router for all methods usage:

websvr.Any("/api", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*HttpServer) AutoPrefix

func (app *HttpServer) AutoPrefix(prefix string, c ControllerInterface) *HttpServer

AutoPrefix adds controller handler to BhojpurApp with prefix. it's same to HttpServer.AutoRouterWithPrefix. if websvr.AutoPrefix("/admin",&MainController{}) and MainController has methods List and Page, visit the url /admin/main/list to exec List function or /admin/main/page to exec Page function.

func (*HttpServer) AutoRouter

func (app *HttpServer) AutoRouter(c ControllerInterface) *HttpServer

AutoRouter adds defined controller handler to BhojpurApp. it's same to HttpServer.AutoRouter. if websvr.AddAuto(&MainController{}) and MainController has methods List and Page, visit the url /main/list to exec List function or /main/page to exec Page function.

func (*HttpServer) CtrlAny added in v0.0.4

func (app *HttpServer) CtrlAny(rootpath string, f interface{}) *HttpServer

CtrlAny used to register router for CtrlAny method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlAny("/api/:id", MyController.Ping)

func (*HttpServer) CtrlDelete added in v0.0.4

func (app *HttpServer) CtrlDelete(rootpath string, f interface{}) *HttpServer

CtrlDelete used to register router for CtrlDelete method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlDelete("/api/:id", MyController.Ping)

func (*HttpServer) CtrlGet added in v0.0.4

func (app *HttpServer) CtrlGet(rootpath string, f interface{}) *HttpServer

CtrlGet used to register router for CtrlGet method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlGet("/api/:id", MyController.Ping)

func (*HttpServer) CtrlHead added in v0.0.4

func (app *HttpServer) CtrlHead(rootpath string, f interface{}) *HttpServer

CtrlHead used to register router for CtrlHead method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlHead("/api/:id", MyController.Ping)

func (*HttpServer) CtrlOptions added in v0.0.4

func (app *HttpServer) CtrlOptions(rootpath string, f interface{}) *HttpServer

CtrlOptions used to register router for CtrlOptions method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlOptions("/api/:id", MyController.Ping)

func (*HttpServer) CtrlPatch added in v0.0.4

func (app *HttpServer) CtrlPatch(rootpath string, f interface{}) *HttpServer

CtrlPatch used to register router for CtrlPatch method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlPatch("/api/:id", MyController.Ping)

func (*HttpServer) CtrlPost added in v0.0.4

func (app *HttpServer) CtrlPost(rootpath string, f interface{}) *HttpServer

CtrlPost used to register router for CtrlPost method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlPost("/api/:id", MyController.Ping)

func (*HttpServer) CtrlPut added in v0.0.4

func (app *HttpServer) CtrlPut(rootpath string, f interface{}) *HttpServer

CtrlPut used to register router for CtrlPut method usage:

   type MyController struct {
	     web.Controller
   }
   func (m MyController) Ping() {
	     m.Ctx.Output.Body([]byte("hello world"))
   }

   CtrlPut("/api/:id", MyController.Ping)

func (*HttpServer) Delete

func (app *HttpServer) Delete(rootpath string, f HandleFunc) *HttpServer

Delete used to register router for Delete method usage:

websvr.Delete("/api", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*HttpServer) Get

func (app *HttpServer) Get(rootpath string, f HandleFunc) *HttpServer

Get used to register router for Get method usage:

websvr.Get("/", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*HttpServer) Handler

func (app *HttpServer) Handler(rootpath string, h http.Handler, options ...interface{}) *HttpServer

Handler used to register a Handler router usage:

websvr.Handler("/api", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
      fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
}))

func (*HttpServer) Head

func (app *HttpServer) Head(rootpath string, f HandleFunc) *HttpServer

Head used to register router for Head method usage:

websvr.Head("/api", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*HttpServer) Include

func (app *HttpServer) Include(cList ...ControllerInterface) *HttpServer

Include will generate router file in the router/xxx.go from the controller's comments usage: websvr.Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})

type BankAccount struct{
  websvr.Controller
}

register the function

func (b *BankAccount)Mapping(){
 b.Mapping("ShowAccount" , b.ShowAccount)
 b.Mapping("ModifyAccount", b.ModifyAccount)
}

//@router /account/:id [get]

func (b *BankAccount) ShowAccount(){
   //logic
}

//@router /account/:id [post]

func (b *BankAccount) ModifyAccount(){
   //logic
}

the comments @router url methodlist url support all the function Router's pattern methodlist [get post head put delete options *]

func (*HttpServer) InsertFilter

func (app *HttpServer) InsertFilter(pattern string, pos int, filter FilterFunc, opts ...FilterOpt) *HttpServer

InsertFilter adds a FilterFunc with pattern condition and action constant. The pos means action constant including websvr.BeforeStatic, websvr.BeforeRouter, websvr.BeforeExec, websvr.AfterExec and websvr.FinishRouter. The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)

func (*HttpServer) InsertFilterChain

func (app *HttpServer) InsertFilterChain(pattern string, filterChain FilterChain, opts ...FilterOpt) *HttpServer

InsertFilterChain adds a FilterFunc built by filterChain. This filter will be executed before all filters. the filter's behavior like stack's behavior and the last filter is serving the http request

func (*HttpServer) LogAccess

func (app *HttpServer) LogAccess(ctx *ctxsvr.Context, startTime *time.Time, statusCode int)

func (*HttpServer) Options

func (app *HttpServer) Options(rootpath string, f HandleFunc) *HttpServer

Options used to register router for Options method usage:

websvr.Options("/api", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*HttpServer) Patch

func (app *HttpServer) Patch(rootpath string, f HandleFunc) *HttpServer

Patch used to register router for Patch method usage:

websvr.Patch("/api", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*HttpServer) Post

func (app *HttpServer) Post(rootpath string, f HandleFunc) *HttpServer

Post used to register router for Post method usage:

websvr.Post("/api", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*HttpServer) PrintTree

func (app *HttpServer) PrintTree() M

PrintTree prints all registered routers.

func (*HttpServer) Put

func (app *HttpServer) Put(rootpath string, f HandleFunc) *HttpServer

Put used to register router for Put method usage:

websvr.Put("/api", func(ctx *context.Context){
      ctx.Output.Body("hello world")
})

func (*HttpServer) RESTRouter

func (app *HttpServer) RESTRouter(rootpath string, c ControllerInterface) *HttpServer

RESTRouter adds a restful controller handler to BhojpurApp. its' controller implements websvr.ControllerInterface and defines a param "pattern/:objectId" to visit each resource.

func (*HttpServer) Router

func (app *HttpServer) Router(rootPath string, c ControllerInterface, mappingMethods ...string) *HttpServer

Router adds a patterned controller handler to BhojpurApp. it's an alias method of HttpServer.Router. usage:

simple router
websvr.Router("/admin", &admin.UserController{})
websvr.Router("/admin/index", &admin.ArticleController{})

regex router

websvr.Router("/api/:id([0-9]+)", &controllers.RController{})

custom rules
websvr.Router("/api/list",&RestController{},"*:ListFood")
websvr.Router("/api/create",&RestController{},"post:CreateFood")
websvr.Router("/api/update",&RestController{},"put:UpdateFood")
websvr.Router("/api/delete",&RestController{},"delete:DeleteFood")

func (*HttpServer) RouterWithOpts added in v0.0.4

func (app *HttpServer) RouterWithOpts(rootPath string, c ControllerInterface, opts ...ControllerOption) *HttpServer

func (*HttpServer) Run

func (app *HttpServer) Run(addr string, mws ...MiddleWare)

Run the Bhojpur.NET Platform's primary web server engine.

func (*HttpServer) UnregisterFixedRoute

func (app *HttpServer) UnregisterFixedRoute(fixedRoute string, method string) *HttpServer

UnregisterFixedRoute unregisters the route with the specified fixedRoute. It is particularly useful in web applications that inherit most routes from a base webapp via the underscore import, and aim to overwrite only certain paths. The method parameter can be empty or "*" for all HTTP methods, or a particular method type (e.g. "GET" or "POST") for selective removal.

Usage (replace "GET" with "*" for all methods):

websvr.UnregisterFixedRoute("/yourpreviouspath", "GET")
websvr.Router("/yourpreviouspath", yourControllerAddress, "get:GetNewPage")

type LinkNamespace

type LinkNamespace func(*Namespace)

LinkNamespace used as link action

func NSAfter

func NSAfter(filterList ...FilterFunc) LinkNamespace

NSAfter add Namespace FinishRouter filter

func NSAny

func NSAny(rootpath string, f HandleFunc) LinkNamespace

NSAny call Namespace Any

func NSAutoPrefix

func NSAutoPrefix(prefix string, c ControllerInterface) LinkNamespace

NSAutoPrefix call Namespace AutoPrefix

func NSAutoRouter

func NSAutoRouter(c ControllerInterface) LinkNamespace

NSAutoRouter call Namespace AutoRouter

func NSBefore

func NSBefore(filterList ...FilterFunc) LinkNamespace

NSBefore Namespace BeforeRouter filter

func NSCond

func NSCond(cond namespaceCond) LinkNamespace

NSCond is Namespace Condition

func NSCtrlAny added in v0.0.4

func NSCtrlAny(rootpath string, f interface{}) LinkNamespace

NSCtrlAny call Namespace CtrlAny

func NSCtrlDelete added in v0.0.4

func NSCtrlDelete(rootpath string, f interface{}) LinkNamespace

NSCtrlDelete call Namespace CtrlDelete

func NSCtrlGet added in v0.0.4

func NSCtrlGet(rootpath string, f interface{}) LinkNamespace

NSCtrlGet call Namespace CtrlGet

func NSCtrlHead added in v0.0.4

func NSCtrlHead(rootpath string, f interface{}) LinkNamespace

NSCtrlHead call Namespace CtrlHead

func NSCtrlOptions added in v0.0.4

func NSCtrlOptions(rootpath string, f interface{}) LinkNamespace

NSCtrlOptions call Namespace CtrlOptions

func NSCtrlPatch added in v0.0.4

func NSCtrlPatch(rootpath string, f interface{}) LinkNamespace

NSCtrlPatch call Namespace CtrlPatch

func NSCtrlPost added in v0.0.4

func NSCtrlPost(rootpath string, f interface{}) LinkNamespace

NSCtrlPost call Namespace CtrlPost

func NSCtrlPut added in v0.0.4

func NSCtrlPut(rootpath string, f interface{}) LinkNamespace

NSCtrlPut call Namespace CtrlPut

func NSDelete

func NSDelete(rootpath string, f HandleFunc) LinkNamespace

NSDelete call Namespace Delete

func NSGet

func NSGet(rootpath string, f HandleFunc) LinkNamespace

NSGet call Namespace Get

func NSHandler

func NSHandler(rootpath string, h http.Handler) LinkNamespace

NSHandler add handler

func NSHead

func NSHead(rootpath string, f HandleFunc) LinkNamespace

NSHead call Namespace Head

func NSInclude

func NSInclude(cList ...ControllerInterface) LinkNamespace

NSInclude Namespace Include ControllerInterface

func NSNamespace

func NSNamespace(prefix string, params ...LinkNamespace) LinkNamespace

NSNamespace add sub Namespace

func NSOptions

func NSOptions(rootpath string, f HandleFunc) LinkNamespace

NSOptions call Namespace Options

func NSPatch

func NSPatch(rootpath string, f HandleFunc) LinkNamespace

NSPatch call Namespace Patch

func NSPost

func NSPost(rootpath string, f HandleFunc) LinkNamespace

NSPost call Namespace Post

func NSPut

func NSPut(rootpath string, f HandleFunc) LinkNamespace

NSPut call Namespace Put

func NSRouter

func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) LinkNamespace

NSRouter call Namespace Router

type Listen

type Listen struct {
	// Graceful
	// @Description means use graceful module to start the server
	// @Default false
	Graceful bool
	// ListenTCP4
	// @Description if it's true, means that Bhojpur Web only work for TCP4
	// please check net.Listen function
	// In general, you should not set it to true
	// @Default false
	ListenTCP4 bool
	// EnableHTTP
	// @Description if it's true, Bhojpur Web will accept HTTP request.
	// But if you want to use HTTPS only, please set it to false
	// see EnableHTTPS
	// @Default true
	EnableHTTP bool
	// AutoTLS
	// @Description If it's true, Bhojpur Web will use default value to initialize the TLS configure
	// But those values could be override if you have custom value.
	// see Domains, TLSCacheDir
	// @Default false
	AutoTLS bool
	// EnableHTTPS
	// @Description If it's true, Bhojpur Web will accept HTTPS request.
	// Now, you'd better use HTTPS protocol on prod environment to get better security
	// In prod, the best option is EnableHTTPS=true and EnableHTTP=false
	// see EnableHTTP
	// @Default false
	EnableHTTPS bool
	// EnableMutualHTTPS
	// @Description if it's true, Bhojpur Web will handle requests on incoming mutual TLS connections
	// see Server.ListenAndServeMutualTLS
	// @Default false
	EnableMutualHTTPS bool
	// EnableAdmin
	// @Description if it's true, Bhojpur Web will provide admin service.
	// You can visit the admin service via browser.
	// The default port is 8088
	// see AdminPort
	// @Default false
	EnableAdmin bool
	// EnableFcgi
	// @Description
	// @Default false
	EnableFcgi bool
	// EnableStdIo
	// @Description EnableStdIo works with EnableFcgi Use FCGI via standard I/O
	// @Default false
	EnableStdIo bool
	// ServerTimeOut
	// @Description Bhojpur Web use this as ReadTimeout and WriteTimeout
	// The unit is second.
	// see http.Server.ReadTimeout, WriteTimeout
	// @Default 0
	ServerTimeOut int64
	// HTTPAddr
	// @Description Bhojpur Web listen to this address when the application start up.
	// @Default ""
	HTTPAddr string
	// HTTPPort
	// @Description Bhojpur Web listen to this port
	// you'd better change this value when you deploy to prod environment
	// @Default 8080
	HTTPPort int
	// Domains
	// @Description Bhojpur Web use this to configure TLS. Those domains are "white list" domain
	// @Default []
	Domains []string
	// TLSCacheDir
	// @Description Bhojpur Web use this as cache dir to store TLS cert data
	// @Default ""
	TLSCacheDir string
	// HTTPSAddr
	// @Description Bhojpur Web will listen to this address to accept HTTPS request
	// see EnableHTTPS
	// @Default ""
	HTTPSAddr string
	// HTTPSPort
	// @Description  Bhojpur Web will listen to this port to accept HTTPS request
	// @Default 10443
	HTTPSPort int
	// HTTPSCertFile
	// @Description Bhojpur Web read this file as cert file
	// When you are using HTTPS protocol, please configure it
	// see HTTPSKeyFile
	// @Default ""
	HTTPSCertFile string
	// HTTPSKeyFile
	// @Description Bhojpur Web read this file as key file
	// When you are using HTTPS protocol, please configure it
	// see HTTPSCertFile
	// @Default ""
	HTTPSKeyFile string
	// TrustCaFile
	// @Description Bhojpur Web read this file as CA file
	// @Default ""
	TrustCaFile string
	// AdminAddr
	// @Description Bhojpur Web will listen to this address to provide admin service
	// In general, it should be the same with your application address, HTTPAddr or HTTPSAddr
	// @Default ""
	AdminAddr string
	// AdminPort
	// @Description  Bhojpur Web will listen to this port to provide admin service
	// @Default 8088
	AdminPort int
	// @Description Bhojpur Web use this tls.ClientAuthType to initialize TLS connection
	// The default value is tls.RequireAndVerifyClientCert
	// @Default 4
	ClientAuth int
}

Listen holds for http and https related config

type LogConfig

type LogConfig struct {
	// AccessLogs
	// @Description If it's true, Bhojpur Web will log the HTTP request info
	// @Default false
	AccessLogs bool
	// EnableStaticLogs
	// @Description log static files requests
	// @Default false
	EnableStaticLogs bool
	// FileLineNum
	// @Description if it's true, it will log the line number
	// @Default true
	FileLineNum bool
	// AccessLogsFormat
	// @Description access log format: JSON_FORMAT, APACHE_FORMAT or empty string
	// @Default APACHE_FORMAT
	AccessLogsFormat string
	// Outputs
	// @Description the destination of access log
	// the key is log adapter and the value is adapter's configure
	// @Default "console" => ""
	Outputs map[string]string // Store Adaptor : config
}

LogConfig holds Log related config

type M

type M map[string]interface{}

M is Map shortcut

func PrintTree

func PrintTree() M

PrintTree print all routers Deprecated using BhojpurApp directly

type MiddleWare

type MiddleWare func(http.Handler) http.Handler

MiddleWare function for http.Handler

type Namespace

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

Namespace is store all the info

func NewNamespace

func NewNamespace(prefix string, params ...LinkNamespace) *Namespace

NewNamespace get new Namespace

func (*Namespace) Any

func (n *Namespace) Any(rootpath string, f HandleFunc) *Namespace

Any same as websvr.Any

func (*Namespace) AutoPrefix

func (n *Namespace) AutoPrefix(prefix string, c ControllerInterface) *Namespace

AutoPrefix same as websvr.AutoPrefix

func (*Namespace) AutoRouter

func (n *Namespace) AutoRouter(c ControllerInterface) *Namespace

AutoRouter same as websvr.AutoRouter

func (*Namespace) Cond

func (n *Namespace) Cond(cond namespaceCond) *Namespace

Cond set condition function if cond return true can run this namespace, else can't usage:

ns.Cond(func (ctx *context.Context) bool{
      if ctx.Input.Domain() == "api.bhojpur.net" {
        return true
      }
      return false
  })

Cond as the first filter

func (*Namespace) CtrlAny added in v0.0.4

func (n *Namespace) CtrlAny(rootpath string, f interface{}) *Namespace

Any same as websvr.CtrlAny

func (*Namespace) CtrlDelete added in v0.0.4

func (n *Namespace) CtrlDelete(rootpath string, f interface{}) *Namespace

CtrlDelete same as websvr.CtrlDelete

func (*Namespace) CtrlGet added in v0.0.4

func (n *Namespace) CtrlGet(rootpath string, f interface{}) *Namespace

CtrlGet same as websvr.CtrlGet

func (*Namespace) CtrlHead added in v0.0.4

func (n *Namespace) CtrlHead(rootpath string, f interface{}) *Namespace

CtrlHead same as websvr.CtrlHead

func (*Namespace) CtrlOptions added in v0.0.4

func (n *Namespace) CtrlOptions(rootpath string, f interface{}) *Namespace

CtrlOptions same as websvr.CtrlOptions

func (*Namespace) CtrlPatch added in v0.0.4

func (n *Namespace) CtrlPatch(rootpath string, f interface{}) *Namespace

CtrlPatch same as websvr.CtrlPatch

func (*Namespace) CtrlPost added in v0.0.4

func (n *Namespace) CtrlPost(rootpath string, f interface{}) *Namespace

CtrlPost same as websvr.CtrlPost

func (*Namespace) CtrlPut added in v0.0.4

func (n *Namespace) CtrlPut(rootpath string, f interface{}) *Namespace

CtrlPut same as websvr.CtrlPut

func (*Namespace) Delete

func (n *Namespace) Delete(rootpath string, f HandleFunc) *Namespace

Delete same as websvr.Delete

func (*Namespace) Filter

func (n *Namespace) Filter(action string, filter ...FilterFunc) *Namespace

Filter add filter in the Namespace action has before & after FilterFunc usage:

Filter("before", func (ctx *context.Context){
      _, ok := ctx.Input.Session("uid").(int)
      if !ok && ctx.Request.RequestURI != "/login" {
         ctx.Redirect(302, "/login")
       }
  })

func (*Namespace) Get

func (n *Namespace) Get(rootpath string, f HandleFunc) *Namespace

Get same as websvr.Get

func (*Namespace) Handler

func (n *Namespace) Handler(rootpath string, h http.Handler) *Namespace

Handler same as websvr.Handler

func (*Namespace) Head

func (n *Namespace) Head(rootpath string, f HandleFunc) *Namespace

Head same as websvr.Head

func (*Namespace) Include

func (n *Namespace) Include(cList ...ControllerInterface) *Namespace

Include add include class

func (*Namespace) Namespace

func (n *Namespace) Namespace(ns ...*Namespace) *Namespace

Namespace add nest Namespace usage: ns := websvr.NewNamespace(“/v1”). Namespace(

websvr.NewNamespace("/shop").
    Get("/:id", func(ctx *context.Context) {
        ctx.Output.Body([]byte("shopinfo"))
}),
websvr.NewNamespace("/order").
    Get("/:id", func(ctx *context.Context) {
        ctx.Output.Body([]byte("orderinfo"))
}),
websvr.NewNamespace("/crm").
    Get("/:id", func(ctx *context.Context) {
        ctx.Output.Body([]byte("crminfo"))
}),

)

func (*Namespace) Options

func (n *Namespace) Options(rootpath string, f HandleFunc) *Namespace

Options same as websvr.Options

func (*Namespace) Patch

func (n *Namespace) Patch(rootpath string, f HandleFunc) *Namespace

Patch same as websvr.Patch

func (*Namespace) Post

func (n *Namespace) Post(rootpath string, f HandleFunc) *Namespace

Post same as websvr.Post

func (*Namespace) Put

func (n *Namespace) Put(rootpath string, f HandleFunc) *Namespace

Put same as websvr.Put

func (*Namespace) Router

func (n *Namespace) Router(rootpath string, c ControllerInterface, mappingMethods ...string) *Namespace

Router same as websvr.Router

type PolicyFunc

type PolicyFunc func(*context.Context)

PolicyFunc defines a policy function which is invoked before the controller handler is executed.

type SessionConfig

type SessionConfig struct {
	// SessionOn
	// @Description if it's true, Bhojpur Web will auto manage session
	// @Default false
	SessionOn bool
	// SessionAutoSetCookie
	// @Description if it's true, Bhojpur Web will put the session token into cookie too
	// @Default true
	SessionAutoSetCookie bool
	// SessionDisableHTTPOnly
	// @Description used to allow for cross domain cookies/javascript cookies
	// In general, you should not set it to true unless you understand the risk
	// @Default false
	SessionDisableHTTPOnly bool
	// SessionEnableSidInHTTPHeader
	// @Description enable store/get the sessionId into/from http headers
	// @Default false
	SessionEnableSidInHTTPHeader bool
	// SessionEnableSidInURLQuery
	// @Description enable get the sessionId from Url Query params
	// @Default false
	SessionEnableSidInURLQuery bool
	// SessionProvider
	// @Description session provider's name.
	// You should confirm that this provider has been register via session.Register method
	// the default value is memory. This is not suitable for distributed system
	// @Default memory
	SessionProvider string
	// SessionName
	// @Description If SessionAutoSetCookie is true, we use this value as the cookie's name
	// @Default bhojpursessionID
	SessionName string
	// SessionGCMaxLifetime
	// @Description Bhojpur Web will GC session to clean useless session.
	// unit: second
	// @Default 3600
	SessionGCMaxLifetime int64
	// SessionProviderConfig
	// @Description the config of session provider
	// see SessionProvider
	// you should read the document of session provider to learn how to set this value
	// @Default ""
	SessionProviderConfig string
	// SessionCookieLifeTime
	// @Description If SessionAutoSetCookie is true,
	// we use this value as the expiration time and max age of the cookie
	// unit second
	// @Default 0
	SessionCookieLifeTime int
	// SessionDomain
	// @Description If SessionAutoSetCookie is true, we use this value as the cookie's domain
	// @Default ""
	SessionDomain string
	// SessionNameInHTTPHeader
	// @Description if SessionEnableSidInHTTPHeader is true, this value will be used as the http header
	// @Default Bhojpursessionid
	SessionNameInHTTPHeader string
	// SessionCookieSameSite
	// @Description If SessionAutoSetCookie is true, we use this value as the cookie's same site policy
	// the default value is http.SameSiteDefaultMode
	// @Default 1
	SessionCookieSameSite http.SameSite

	// SessionIDPrefix
	// @Description session id's prefix
	// @Default ""
	SessionIDPrefix string
}

SessionConfig holds session related config

type Statistics

type Statistics struct {
	RequestURL        string
	RequestController string
	RequestNum        int64
	MinTime           time.Duration
	MaxTime           time.Duration
	TotalTime         time.Duration
}

Statistics struct

type Tree

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

Tree has three elements: FixRouter/wildcard/leaves fixRouter stores Fixed Router wildcard stores params leaves store the endpoint information

func NewTree

func NewTree() *Tree

NewTree return a new Tree

func (*Tree) AddRouter

func (t *Tree) AddRouter(pattern string, runObject interface{})

AddRouter call addseg function

func (*Tree) AddTree

func (t *Tree) AddTree(prefix string, tree *Tree)

AddTree will add tree to the exist Tree prefix should has no params

func (*Tree) Match

func (t *Tree) Match(pattern string, ctx *context.Context) (runObject interface{})

Match router to runObject & params

type URLMap

type URLMap struct {
	LengthLimit int // limit the urlmap's length if it's equal to 0 there's no limit
	// contains filtered or unexported fields
}

URLMap contains several statistics struct to log different data

var StatisticsMap *URLMap

StatisticsMap hosld global statistics data map

func (*URLMap) AddStatistics

func (m *URLMap) AddStatistics(requestMethod, requestURL, requestController string, requesttime time.Duration)

AddStatistics add statistics task. it needs request method, request url, request controller and statistics time duration

func (*URLMap) GetMap

func (m *URLMap) GetMap() map[string]interface{}

GetMap put url statistics result in io.Writer

func (*URLMap) GetMapData

func (m *URLMap) GetMapData() []map[string]interface{}

GetMapData return all mapdata

type WebConfig

type WebConfig struct {
	// AutoRender
	// @Description If it's true, Bhojpur Web will render the page based on your template and data
	// In general, keep it as true.
	// But if you are building RESTFul API and you don't have any page,
	// you can set it to false
	// @Default true
	AutoRender bool
	// Deprecated: Bhojpur Web didn't use it anymore
	EnableDocs bool
	// EnableXSRF
	// @Description If it's true, Bhojpur Web will help to provide XSRF support
	// But you should notice that, now Bhojpur Web only work for HTTPS protocol with XSRF
	// because it's not safe if using HTTP protocol
	// And, the cookie storing XSRF token has two more flags HttpOnly and Secure
	// It means that you must use HTTPS protocol and you can not read the token from JS script
	// This is completed different from Bhojpur Web 1.x because we got many security reports
	// And if you are in dev environment, you could set it to false
	// @Default false
	EnableXSRF bool
	// DirectoryIndex
	// @Description When Bhojpur Web serves static resources request, it will look up the file.
	// If the file is directory, Bhojpur Web will try to find the index.html as the response
	// But if the index.html is not exist or it's a directory,
	// Bhojpur Web will return 403 response if DirectoryIndex is **false**
	// @Default false
	DirectoryIndex bool
	// FlashName
	// @Description the cookie's name when Bhojpur Web try to store the flash data into cookie
	// @Default BHOJPUR_FLASH
	FlashName string
	// FlashSeparator
	// @Description When Bhojpur Web read flash data from request, it uses this as the separator
	// @Default BHOJPURFLASH
	FlashSeparator string
	// StaticDir
	// @Description Bhojpur Web uses this as static resources' root directory.
	// It means that Bhojpur Web will try to search static resource from this start point
	// It's a map, the key is the path and the value is the directory
	// For example, the default value is /static => static,
	// which means that when Bhojpur Web got a request with path /static/xxx
	// Bhojpur Web will try to find the resource from static directory
	// @Default /static => static
	StaticDir map[string]string
	// StaticExtensionsToGzip
	// @Description The static resources with those extension will be compressed if EnableGzip is true
	// @Default [".css", ".js" ]
	StaticExtensionsToGzip []string
	// StaticCacheFileSize
	// @Description If the size of static resource < StaticCacheFileSize, Bhojpur Web will try to handle it by itself,
	// it means that Bhojpur Web will compressed the file data (if enable) and cache this file.
	// But if the file size > StaticCacheFileSize, Bhojpur Web just simply delegate the request to http.ServeFile
	// the default value is 100KB.
	// the max memory size of caching static files is StaticCacheFileSize * StaticCacheFileNum
	// see StaticCacheFileNum
	// @Default 102400
	StaticCacheFileSize int
	// StaticCacheFileNum
	// @Description Bhojpur Web use it to control the memory usage of caching static resource file
	// If the caching files > StaticCacheFileNum, Bhojpur Web uses LRU algorithm to remove caching file
	// the max memory size of caching static files is StaticCacheFileSize * StaticCacheFileNum
	// see StaticCacheFileSize
	// @Default 1000
	StaticCacheFileNum int
	// TemplateLeft
	// @Description Bhojpur Web use this to render page
	// see TemplateRight
	// @Default {{
	TemplateLeft string
	// TemplateRight
	// @Description Bhojpur Web use this to render page
	// see TemplateLeft
	// @Default }}
	TemplateRight string
	// ViewsPath
	// @Description The directory of Bhojpur Web application storing template
	// @Default views
	ViewsPath string
	// CommentRouterPath
	// @Description Bhojpur Web scans this directory and its sub directory to generate router
	// Bhojpur Web only scans this directory when it's in dev environment
	// @Default controllers
	CommentRouterPath string
	// XSRFKey
	// @Description the name of cookie storing XSRF token
	// see EnableXSRF
	// @Default bhojpurxsrf
	XSRFKey string
	// XSRFExpire
	// @Description the expiration time of XSRF token cookie
	// second
	// @Default 0
	XSRFExpire int
	// @Description session related config
	Session SessionConfig
}

WebConfig holds web related config

Jump to

Keyboard shortcuts

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