W

package
v1.4012.332 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const ERROR_DEFAULT_CONTENT = `` /* 2226-byte string literal not displayed */

locals: error_code, error_title, error_detail, project_name, requested_path, webmaster

View Source
const LAYOUT_DEFAULT_CONTENT = `` /* 2286-byte string literal not displayed */

locals: title, project_name, assets, contents, is_superadmin, debug_mode

View Source
const LOG_SUBDIR = `logs/`
View Source
const NS2SEC = 1000 * 1000 * 1000
View Source
const PUBLIC_SUBDIR = `public/`
View Source
const VIEWS_SUBDIR = `views/`

Variables

View Source
var Assets [][2]string // []{{`js css /js /css`,`filename`}, ...}
View Source
var DEFAULT_FILEDIR_PERM = os.FileMode(0755)
View Source
var EXPIRE_SEC int64
View Source
var Errors = map[int]string{
	0:   `Unknown Error`,
	500: `Internal Server Error`,
	404: `Page Not Found`,
	403: `Forbidden`,
	503: `Server is Overloaded`,
}
View Source
var Filters []Action
View Source
var MIME2EXT = map[string]string{
	`application/pdf`: `pdf`,
	`image/png`:       `png`,
	`image/jpeg`:      `jpg`,
	`application/zip`: `zip`,
}
View Source
var Mailers map[string]*SmtpConfig // used in mailer.go
View Source
var RENEW_SEC int64
View Source
var Routes map[string]Action
View Source
var SESS_KEY = `SK`
View Source
var Webmasters M.SS // used in engine.go
View Source
var YOUTUBE_MIME2EXT = map[string]string{
	`video/x-flv`:     `flv`,
	`video/mp4`:       `mp4`,
	`video/quicktime`: `mov`,
	`video/x-msvideo`: `avi`,
	`video/x-ms-wmv`:  `wmv`,
	`video/webm`:      `webm`,
	`video/3gpp`:      `3gp`,
	`video/mp2p`:      `mpegps`,
	`video/mp1s`:      `mpegps`,
}

supported by youtube

View Source
var YOUTUBE_MIME_LIST []string

Functions

func InitSession

func InitSession(sess_key string, expire_ns, renew_ns time.Duration, conn SessionConnector, glob SessionConnector)

func LogFilter

func LogFilter(ctx *Context)

func PanicFilter

func PanicFilter(ctx *Context)

func SessionFilter

func SessionFilter(ctx *Context)

Types

type Action

type Action func(controller *Context)

type Ajax

type Ajax struct {
	M.SX
}

func NewAjax

func NewAjax() Ajax

func (Ajax) ClearErrors

func (json Ajax) ClearErrors()

func (Ajax) Error

func (json Ajax) Error(msg string) string

func (Ajax) ErrorIf

func (json Ajax) ErrorIf(err error, msg string) bool

func (Ajax) HasError

func (json Ajax) HasError() bool

func (Ajax) Info

func (json Ajax) Info(msg string)

func (Ajax) LastError

func (json Ajax) LastError() string

func (Ajax) OverwriteInfo

func (json Ajax) OverwriteInfo(msg string)

func (Ajax) TestError

func (json Ajax) TestError(err error, errmsg string) bool

type Context

type Context struct {
	*fasthttp.RequestCtx
	Session     *Session
	Title       string
	Engine      *Engine
	Buffer      bytes.Buffer
	Route       string
	Actions     []Action
	PostCache   *Posts
	NoLayout    bool
	ContentType string
	// contains filtered or unexported fields
}

func (*Context) AppendAjax

func (ctx *Context) AppendAjax(ajax Ajax)

func (*Context) AppendBuffer

func (ctx *Context) AppendBuffer(buff bytes.Buffer)

append buffer

func (*Context) AppendBytes

func (ctx *Context) AppendBytes(buf []byte)

append bytes

func (*Context) AppendMap

func (ctx *Context) AppendMap(any M.SX)

append json

func (*Context) AppendString

func (ctx *Context) AppendString(txt string)

append string

func (*Context) Error

func (ctx *Context) Error(code int, info string)

func (*Context) Finish

func (ctx *Context) Finish()

func (*Context) FirstPath

func (ctx *Context) FirstPath() string

TODO: test this, make sure it returns only first segment

func (*Context) Headers

func (ctx *Context) Headers() M.SS

parse header if first time

func (*Context) Host

func (ctx *Context) Host() string

get requested host

func (*Context) IsAjax

func (ctx *Context) IsAjax() bool

check if request method is POST

func (*Context) IsWebMaster

func (ctx *Context) IsWebMaster() bool

func (*Context) Log

func (ctx *Context) Log(message string)

func (*Context) Next

func (ctx *Context) Next() Action

call next filter or action/handler

func (*Context) ParamBool

func (ctx *Context) ParamBool(key string) bool

get url parameter as boolean

func (*Context) ParamInt

func (ctx *Context) ParamInt(key string) int64

get url parameter as integer

func (*Context) ParamJsonMap

func (ctx *Context) ParamJsonMap(key string) M.SX

get url parameter as M.SX

func (*Context) ParamJsonStrArr

func (ctx *Context) ParamJsonStrArr(key string) []string

get url parameter as []string

func (*Context) ParamStr

func (ctx *Context) ParamStr(key string) string

get url parameter as string

func (*Context) PartialNoDebug

func (ctx *Context) PartialNoDebug(path string, locals M.SX) string

func (*Context) Posts

func (ctx *Context) Posts() *Posts

func (*Context) Proto

func (ctx *Context) Proto() string

protocol

func (*Context) QueryParams

func (ctx *Context) QueryParams() *QueryParams

get parsed ?a=b&c=d, this is different from Param*() func

func (*Context) Render

func (ctx *Context) Render(path string, locals M.SX)

func (*Context) RequestDebugStr

func (ctx *Context) RequestDebugStr() string

debug info

func (*Context) RequestHtmlStr

func (ctx *Context) RequestHtmlStr() string

non debug info

func (*Context) RequestLogStr

func (ctx *Context) RequestLogStr() string

debug info

func (*Context) RequestURL

func (ctx *Context) RequestURL() string

request URL

func (*Context) UploadedFile

func (ctx *Context) UploadedFile(id string) (fileName, ext, contentType string, reader multipart.File)

uploaded file

type Engine

type Engine struct {
	DebugMode bool
	MultiApp  bool
	// contact if there's bug
	WebMasterAnchor string
	// view template cache
	ViewCache *cmap.CMap
	// global variables
	GlobalInt M.SI
	GlobalStr M.SS
	GlobalAny M.SX
	Router    *fasthttprouter.Router
	// project_name
	Name string
	// location of the project, will be concatenated with VIEWS_SUBDIR, PUBLIC_SUBDIR
	BaseDir   string
	PublicDir string // with slash
	Logger    *os.File
	LogPath   string
	// server creation time
	CreatedAt time.Time
	// assets <script and <link as string
	Assets string
}

func NewEngine

func NewEngine(debugMode, multiApp bool, projectName, baseDir string) *Engine

func (*Engine) LoadLayout

func (engine *Engine) LoadLayout()

func (*Engine) Log

func (engine *Engine) Log(message string)

func (*Engine) MinifyAssets

func (engine *Engine) MinifyAssets()

minify assets

func (*Engine) SendDebugMail

func (engine *Engine) SendDebugMail(message string)

send debug mail

func (*Engine) SendMail

func (engine *Engine) SendMail(mail_id string, bcc []string, subject string, message string)

send email and ignore error

func (*Engine) SendMailSync

func (engine *Engine) SendMailSync(mail_id string, bcc []string, subject string, message string) string

send email and return error

func (*Engine) StartServer

func (engine *Engine) StartServer(addressPort string)

start the server

func (*Engine) Template

func (engine *Engine) Template(key string) *Z.TemplateChain

type Posts

type Posts struct {
	*fasthttp.Args
	M.SS
}

func (*Posts) FromContext

func (p *Posts) FromContext(ctx *Context)

func (*Posts) GetBool

func (p *Posts) GetBool(key string) bool

func (*Posts) GetJsonIntArr

func (p *Posts) GetJsonIntArr(key string) []int64

func (*Posts) GetJsonMap

func (p *Posts) GetJsonMap(key string) M.SX

func (*Posts) GetJsonObjArr

func (p *Posts) GetJsonObjArr(key string) []map[string]interface{}

func (*Posts) GetJsonStrArr

func (p *Posts) GetJsonStrArr(key string) []string

func (*Posts) IsSet

func (p *Posts) IsSet(key string) bool

func (*Posts) NewlineString

func (p *Posts) NewlineString() string

func (*Posts) String

func (p *Posts) String() string

censor the password string, also when length is too long

type QueryParams

type QueryParams struct {
	*fasthttp.Args
}

func (*QueryParams) GetFloat

func (p *QueryParams) GetFloat(key string) float64

func (*QueryParams) GetInt

func (p *QueryParams) GetInt(key string) int64

func (*QueryParams) GetStr

func (p *QueryParams) GetStr(key string) string

type RequestModel

type RequestModel struct {
	Id      string
	Uniq    string
	AppId   string
	Posts   *Posts
	Ajax    Ajax
	DbActor string
	Actor   string
	Level   M.SX
	Ctx     *Context
	Ok      bool
	Action  string
}

func NewRequestModel_ById_ByDbActor_ByAjax

func NewRequestModel_ById_ByDbActor_ByAjax(id, db_actor string, ajax Ajax) *RequestModel

func NewRequestModel_ByUniq_ByDbActor_ByAjax

func NewRequestModel_ByUniq_ByDbActor_ByAjax(uniq_id string, db_actor string, ajax Ajax) *RequestModel

func (*RequestModel) IdInt

func (rm *RequestModel) IdInt() int64

func (*RequestModel) IsAjax

func (rm *RequestModel) IsAjax() bool

type Session

type Session struct {
	UserAgent string
	IpAddr    string
	Key       string
	M.SX
	Changed bool
}

func (*Session) HeaderString

func (s *Session) HeaderString() string

func (*Session) Load

func (s *Session) Load(ctx *Context)

should be called after receiving request

func (*Session) Login

func (s *Session) Login(val M.SX)

func (*Session) Logout

func (s *Session) Logout()

func (*Session) NewlineString

func (s *Session) NewlineString() string

func (*Session) RandomKey

func (s *Session) RandomKey()

func (*Session) Save

func (s *Session) Save(ctx *Context)

should be called before writing response

func (*Session) StateCSRF

func (s *Session) StateCSRF() string

func (*Session) String

func (s *Session) String() string

func (*Session) Touch

func (s *Session) Touch()

type SessionConnector

type SessionConnector interface {
	// delete key
	Del(key string)
	// get remaining lifespan in seconds
	Expiry(key string) int64
	// set string with remaining lifespan in seconds
	FadeStr(key, val string, ttl int64)
	// set integer with remaining lifespan in seconds
	FadeInt(key string, val int64, ttl int64)
	// set json with remaining lifespan in seconds
	FadeMSX(key string, val M.SX, ttl int64)
	// get string
	GetStr(key string) string
	// get integer
	GetInt(key string) int64
	// get string
	GetMSX(key string) M.SX
	// increment
	Inc(key string) int64
	// increment
	Dec(key string) int64
	// set string
	SetStr(key, val string)
	// set integer
	SetInt(key string, val int64)
	// set json
	SetMSX(key string, val M.SX)
	// set json
	SetMSS(key string, val M.SS)
	// get product name, eg: Pg, Sc, My, Rd
	Product() string

	Lpush(key string, val string)
	Rpush(key string, val string)
	Lrange(key string, first, last int64) []string
}
var Globals SessionConnector // from session.go
var Sessions SessionConnector // from session.go

type SmtpConfig

type SmtpConfig struct {
	Name     string
	Username string
	Password string
	Hostname string
	Port     int
}

func NewMailer

func NewMailer(user, pass, host string, port int) *SmtpConfig

func (*SmtpConfig) Address

func (mc *SmtpConfig) Address() string

func (*SmtpConfig) Auth

func (mc *SmtpConfig) Auth() smtp.Auth

func (*SmtpConfig) From

func (mc *SmtpConfig) From() string

func (*SmtpConfig) SendAttachBCC

func (mc *SmtpConfig) SendAttachBCC(bcc []string, subject string, message string, files []string)

run sendAttachbcc on another goroutine

func (*SmtpConfig) SendBCC

func (mc *SmtpConfig) SendBCC(bcc []string, subject string, message string)

run sendbcc on another goroutine

func (*SmtpConfig) SendRaw

func (m *SmtpConfig) SendRaw(e *email.Email) error

func (*SmtpConfig) SendSyncAttachBCC

func (mc *SmtpConfig) SendSyncAttachBCC(bcc []string, subject string, message string, files []string) string

sendbcc synchronous version, returns error message

func (*SmtpConfig) SendSyncBCC

func (mc *SmtpConfig) SendSyncBCC(bcc []string, subject string, message string) string

sendbcc synchronous version, returns error message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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