|------------| |---------| |----------|
| request | -> | router | -> | actions |
|------------| |---------| |----------|
json
templates
databases
actions/default/hello/index.go
package hello
import "github.com/iwind/TeaGo/actions"
type IndexAction actions.Action
func (this *IndexAction) Run() {
this.WriteString("Hello")
}
actions/default/hello/index.go
package hello
import "github.com/iwind/TeaGo/actions"
type IndexAction actions.Action
func (this *IndexAction) Run(params struct {
Name string
Age int
}) {
this.WriteFormat("Name:%s, Age:%d",
params.Name,
params.Age)
}
package MyProject
import (
"github.com/iwind/TeaGo"
"github.com/iwind/MyProject/actions/default/hello/index"
)
func Start() {
var server = TeaGo.NewServer()
// 注册路由
server.Get("/hello", new(hello.IndexAction))
// 启动服务
server.Start("0.0.0.0:8000")
}