Documentation ¶
Overview ¶
gas is a web framework.
Example ¶
Your project file structure
|-- $GOPATH | |-- src | |--Your_Project_Name | |-- config | |-- default.yaml | |-- controllers | |-- default.go | |-- log | |-- models | |-- routers | |-- routers.go | |-- static | |-- views | |-- main.go
main.go
import ( "Your_Project_Name/routers" "github.com/go-gas/gas" ) // Create gas object with config path // default is config/default.yaml g := gas.New("config/path") // register route routers.RegistRout(g.Router) // run and listen g.Run()
routers.go
import ( "Your_Project_Name/controllers" "github.com/go-gas/gas" ) func RegistRout(r *gas.Router) { r.Get("/", controllers.IndexPage) r.Post("/post/:param", controllers.PostTest) rc := &controllers.RestController{} r.REST("/User", rc) }
controllers.go
package controllers import ( "github.com/go-gas/gas" ) func IndexPage(ctx *gas.Context) error { return ctx.Render("", "views/layout.html", "views/index.html") } func PostTest(ctx *gas.Context) error { a := map[string]string{ "Name": ctx.GetParam("param"), } return ctx.Render(a, "views/layout2.html") }
rest_controller.go
import ( "github.com/go-gas/gas" ) type RestController struct { gas.ControllerInterface } func (rc *RestController) Get(c *gas.Context) error { return c.STRING(200, "Test Get") } func (rc *RestController) Post(c *gas.Context) error { return c.STRING(200, "Test Post") }
Index ¶
- Constants
- func New(configPath ...string) *gas
- type Context
- func (ctx *Context) CloseDB() error
- func (ctx *Context) GetModel() model.ModelInterface
- func (ctx *Context) GetParam(name string) string
- func (ctx *Context) HTML(code int, html string) error
- func (ctx *Context) JSON(status int, data interface{}) error
- func (ctx *Context) Render(data interface{}, tplPath ...string) error
- func (ctx *Context) STRING(status int, data string) error
- type Controller
- type ControllerInterface
- type GasHandler
- type MiddlewareFunc
- type PanicHandler
- type Router
- func (r *Router) Delete(path string, ch GasHandler)
- func (r *Router) Get(path string, ch GasHandler)
- func (r *Router) Head(path string, ch GasHandler)
- func (r *Router) Options(path string, ch GasHandler)
- func (r *Router) Patch(path string, ch GasHandler)
- func (r *Router) Post(path string, ch GasHandler)
- func (r *Router) Put(path string, ch GasHandler)
- func (r *Router) REST(path string, c ControllerInterface)
- func (r *Router) SetNotFoundHandler(h GasHandler)
- func (r *Router) SetPanicHandler(ph PanicHandler)
- func (r *Router) StaticPath(dir string)
- func (r *Router) Use(m interface{})
Constants ¶
View Source
const ( ApplicationJSON = "application/json" ApplicationJSONCharsetUTF8 = ApplicationJSON + "; " + CharsetUTF8 ApplicationJavaScript = "application/javascript" ApplicationJavaScriptCharsetUTF8 = ApplicationJavaScript + "; " + CharsetUTF8 ApplicationXML = "application/xml" ApplicationXMLCharsetUTF8 = ApplicationXML + "; " + CharsetUTF8 ApplicationForm = "application/x-www-form-urlencoded" ApplicationProtobuf = "application/protobuf" ApplicationMsgpack = "application/msgpack" TextHTML = "text/html" TextHTMLCharsetUTF8 = TextHTML + "; " + CharsetUTF8 TextPlain = "text/plain" TextPlainCharsetUTF8 = TextPlain + "; " + CharsetUTF8 MultipartForm = "multipart/form-data" CharsetUTF8 = "charset=utf-8" AcceptEncoding = "Accept-Encoding" Authorization = "Authorization" ContentDisposition = "Content-Disposition" ContentEncoding = "Content-Encoding" ContentLength = "Content-Length" ContentType = "Content-Type" Location = "Location" Upgrade = "Upgrade" Vary = "Vary" WWWAuthenticate = "WWW-Authenticate" XForwardedFor = "X-Forwarded-For" XRealIP = "X-Real-IP" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct { //context.Context *fasthttp.RequestCtx // contains filtered or unexported fields }
func (*Context) GetModel ¶
func (ctx *Context) GetModel() model.ModelInterface
Get model using context in controller
type ControllerInterface ¶
type ControllerInterface interface { }
ControllerInterface defind controller interface
type MiddlewareFunc ¶
type MiddlewareFunc func(GasHandler) GasHandler
MiddlewareFunc middlewarefunc define
type PanicHandler ¶
PanicHandler defined panic handler
type Router ¶
type Router struct { *fasthttprouter.Router // contains filtered or unexported fields }
Router class include httprouter and gas
func (*Router) REST ¶
func (r *Router) REST(path string, c ControllerInterface)
REST for set all REST route
func (*Router) SetNotFoundHandler ¶
func (r *Router) SetNotFoundHandler(h GasHandler)
SetNotFoundHandler set Notfound and Panic handler
func (*Router) SetPanicHandler ¶
func (r *Router) SetPanicHandler(ph PanicHandler)
func (*Router) StaticPath ¶
Directories ¶
Path | Synopsis |
---|---|
This package has some of middleware that built-in gas framework.
|
This package has some of middleware that built-in gas framework. |
This package defined and implemented databases model.
|
This package defined and implemented databases model. |
Click to show internal directories.
Click to hide internal directories.