gcontroller

package
v0.0.0-...-8506bae Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 7 Imported by: 0

README

GMC CONTROLLER

METHOD RULES

The rules about controller's method is below.

  1. controller's method has a __ or _ suffix, method will be ignored by router.Controller().

  2. controller's method named Before() is the construct method of controller, will be called before actual method call.

  3. controller's method named After() is the destruct method, will be called after actual method call.

HELPER METHODS

GMC Controller defined some helper methods, help you to coding more easy.

  1. Stop(), call it, your code will exit current requested controller's method.

  2. Die(), call it, your code will exit current requested controller's method, and prevent After be called.

  3. StopE(error,failFunc,okayFunc func()), error check helper, if error is nil, optional failFunc be called, and your code will exit current requested controller's method. Otherwise, optional okayFunc will be called.

INSIDE METHODS

These inside controller's methods, don't call them in your code.

  1. MethodCallPre(), this method is be called before Before to initialize base objects.

  2. MethodCallPost(), this method is be called after After to do some ending works.

  3. Tr, this is a i18n helper function, get details to read about i18n/README.md.

  4. SessionStart() start a session, before you access session data, you must call SessionStart to start session.

  5. SessionDestroy() destroy current session data.

METHOD DEFINE

Your controller extends gcontroller.Controller, so you must not be defined methods above in your controller.

MEMBER DEFINE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller struct {
	Response     http.ResponseWriter
	Request      *http.Request
	Param        gcore.Params
	Session      gcore.Session
	Tpl          gcore.Template
	I18n         gcore.I18n
	SessionStore gcore.SessionStorage
	Router       gcore.HTTPRouter
	Config       gcore.Config
	Cookie       gcore.Cookies
	Ctx          gcore.Ctx
	View         gcore.View
	Lang         string
	Logger       gcore.Logger
}

Controller gmc web and api controller implements gcore.Controller.

func (*Controller) Die

func (this *Controller) Die(msg ...interface{})

Die will prevent to call After() if have, and MethodCallPost()

func (*Controller) GetConfig

func (this *Controller) GetConfig() gcore.Config

func (*Controller) GetCookie

func (this *Controller) GetCookie() gcore.Cookies

func (*Controller) GetCtx

func (this *Controller) GetCtx() gcore.Ctx

func (*Controller) GetI18n

func (this *Controller) GetI18n() gcore.I18n

func (*Controller) GetLang

func (this *Controller) GetLang() string

func (*Controller) GetLogger

func (this *Controller) GetLogger() gcore.Logger

func (*Controller) GetParam

func (this *Controller) GetParam() gcore.Params

func (*Controller) GetRouter

func (this *Controller) GetRouter() gcore.HTTPRouter

func (*Controller) GetSession

func (this *Controller) GetSession() gcore.Session

func (*Controller) GetSessionStore

func (this *Controller) GetSessionStore() gcore.SessionStorage

func (*Controller) GetTemplate

func (this *Controller) GetTemplate() gcore.Template

func (*Controller) GetView

func (this *Controller) GetView() gcore.View

func (*Controller) MethodCallPost

func (this *Controller) MethodCallPost()

MethodCallPost called after controller method and After() if have.

func (*Controller) MethodCallPre

func (this *Controller) MethodCallPre(ctx gcore.Ctx)

MethodCallPre called before controller method and Before() if have.

func (*Controller) SessionDestroy

func (this *Controller) SessionDestroy() (err error)

func (*Controller) SessionStart

func (this *Controller) SessionStart() (err error)

func (*Controller) Stop

func (this *Controller) Stop(msg ...interface{})

Stop will exit controller method at once

func (*Controller) StopE

func (this *Controller) StopE(err interface{}, fn ...func())

StopE will exit controller method if error is not nil. First argument is an error. Secondary argument is fail function, it be called if error is not nil. Third argument is success function, it be called if error is nil.

func (*Controller) Tr

func (this *Controller) Tr(key string, defaultText ...string) string

Tr translates the key to `this.Lang's` text.

func (*Controller) Write

func (this *Controller) Write(data ...interface{}) (n int, err error)

func (*Controller) WriteE

func (this *Controller) WriteE(data ...interface{}) (n int, err error)

Jump to

Keyboard shortcuts

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