Gas aims to be a high performance, full-featured, easy to use, and quick develop backend web application framework in Golang.
- Router (based on fasthttprouter package)
- Easy to use golang template engine. (will include another template engine)
- Context (easy to manage the request and response)
- Middleware (Global and specify routing path middleware support)
- Log package
- Read config from a yaml file gas-config
- Database model (developing, based on go-gas/SQLBuilder)
other features are highly active development
and you can see example at gas-example.
$ go get github.com/go-gas/gas
$ git clone https://github.com/go-gas/example.git && cd example
$ go run main.go
|-- $GOPATH
| |-- src
| |--Your_Project_Name
| |-- config
| |-- default.yaml
| |-- controllers
| |-- default.go
| |-- log
| |-- models
| |-- routers
| |-- routers.go
| |-- static
| |-- views
| |-- main.go
import (
"Your_Project_Name/routers"
"github.com/go-gas/gas"
"github.com/go-gas/gas/middleware"
)
g := gas.New()
g.LoadConfig("your/config/path")
If you don't want to load any config, you might be know that gas have a default config with
var defaultConfig = map[interface{}]interface{}{
"Mode": "DEV",
"ListenAddr": "localhost",
"ListenPort": "8080",
"PubDir": "public",
"Db": map[interface{}]interface{}{
"SqlDriver": "MySQL",
"Hostname": "localhost",
"Port": "3306",
"Username": "root",
"Password": "",
"Charset": "utf8",
},
}
or you can give config path when new gas app
g := gas.New("config/path1", "config/path2")
routers.RegistRout(g.Router)
Then in your routers.go
package routers
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)
}
If you want a middleware to be run during every request to your application, you can use Router.Use function to register your middleware.
g.Router.Use(middleware.LogMiddleware)
If you want to assign middleware to specific routes, you can set your middlewares after set route function like:
r.Get("/", controllers.IndexPage, myMiddleware1, myMiddleware2)
func LogMiddleware(next gas.GasHandler) gas.GasHandler {
return func (c *gas.Context) error {
// do something before next handler
err := next(c)
// do something after next handler
return err
}
}
or
func MyMiddleware2 (ctx *gas.Context) error {
// do something
}
Run and listen your web application with default 8080
port.
g.Run()
or you can give listen address and another port.
g.Run(":8089")
or serving HTTPS (secure) requests.
g.RunTLS(":8080", "CertFile", "CertKey")
but I recommend setting listen address in config files.
Using go-web-framework-benchmark to benchmark with another web fframework.
- Models
- Model fields mapping
- ORM
- Relation mapping
- Transaction
- QueryBuilder
- Session
- Filesystem
- Database
- Redis
- Memcache
- Cache
- Memory
- File
- Redis
- Memcache
- i18n
- HTTPS
- Command line tools
- Form handler (maybe next version)
- Security check features(csrf, xss filter...etc)