项目作者: iwind

项目描述 :
Simple Go Web Framework
高级语言: Go
项目地址: git://github.com/iwind/TeaGo.git
创建时间: 2018-08-23T13:19:11Z
项目社区:https://github.com/iwind/TeaGo

开源协议:

下载


TeaGo - Go语言快速开发框架

  1. |------------| |---------| |----------|
  2. | request | -> | router | -> | actions |
  3. |------------| |---------| |----------|
  4. json
  5. templates
  6. databases

定义不带参数的Action

actions/default/hello/index.go

  1. package hello
  2. import "github.com/iwind/TeaGo/actions"
  3. type IndexAction actions.Action
  4. func (this *IndexAction) Run() {
  5. this.WriteString("Hello")
  6. }

定义带参数的Action

actions/default/hello/index.go

  1. package hello
  2. import "github.com/iwind/TeaGo/actions"
  3. type IndexAction actions.Action
  4. func (this *IndexAction) Run(params struct {
  5. Name string
  6. Age int
  7. }) {
  8. this.WriteFormat("Name:%s, Age:%d",
  9. params.Name,
  10. params.Age)
  11. }

注册Action

  1. package MyProject
  2. import (
  3. "github.com/iwind/TeaGo"
  4. "github.com/iwind/MyProject/actions/default/hello/index"
  5. )
  6. func Start() {
  7. var server = TeaGo.NewServer()
  8. // 注册路由
  9. server.Get("/hello", new(hello.IndexAction))
  10. // 启动服务
  11. server.Start("0.0.0.0:8000")
  12. }