Golang Web Mvc Framework
goku is a Web Mvc Framework for golang, mostly like ASP.NET MVC.
goku is simple and powerful.
Base Features:
now goku is in the
preview version, anything can be change
.
To install goku, simply run go get github.com/QLeelulu/goku
.
To use it in a program, use import "github.com/QLeelulu/goku"
Here is a simple example, or you can check Intro for more detail.
package main
import (
"github.com/QLeelulu/goku"
"log"
"path"
"runtime"
"time"
)
// routes
var routes []*goku.Route = []*goku.Route{
// static file route
&goku.Route{
Name: "static",
IsStatic: true,
Pattern: "/static/(.*)",
},
// default controller and action route
&goku.Route{
Name: "default",
Pattern: "/{controller}/{action}/{id}",
Default: map[string]string{"controller": "home", "action": "index", "id": "0"},
Constraint: map[string]string{"id": "\\d+"},
},
}
// server config
var config *goku.ServerConfig = &goku.ServerConfig{
Addr: ":8888",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
//RootDir: os.Getwd(),
StaticPath: "static",
ViewPath: "views",
Debug: true,
}
func init() {
/**
* project root dir
*/
_, filename, _, _ := runtime.Caller(1)
config.RootDir = path.Dir(filename)
/**
* Controller & Action
*/
goku.Controller("home").
Get("index", func(ctx *goku.HttpContext) goku.ActionResulter {
return ctx.Html("Hello World")
})
}
func main() {
rt := &goku.RouteTable{Routes: routes}
s := goku.CreateServer(rt, nil, config)
goku.Logger().Logln("Server start on", s.Addr)
log.Fatal(s.ListenAndServe())
}
You can found some examples in the github.com/QLeelulu/goku/examples
folder.
To run example “todo” app, just:
$ cd $GOROOT/src/pkg/github.com/QLeelulu/goku/examples/todo/
$ go run app.go
maybe you need run todo.sql
first.
View the LICENSE file.