beego + 返回json测试

// Beego project main.go
package main

import (
    "fmt"
    "github.com/astaxie/beego"
)

type MainController struct {
    beego.Controller
}
type FileController struct {
    beego.Controller
}

func (this *MainController) Get() {
    this.Ctx.WriteString("hello world")
}
func (this *FileController) Post() {
    _, h, err := this.GetFile("file")
    if err != nil {
        fmt.Println("getfile err ", err)
    }
    fmt.Println("filename:", h.Filename)
    this.SaveToFile("file", "e://temp/upload/"+h.Filename)
    this.Ctx.WriteString("hello 1111")
}
func (this *FileController) Get() {
    this.Data["json"] = map[string]interface{}{"success": 0, "message": "111"}
    this.ServeJson()
    return
    //this.Ctx.WriteString("hello 1111")
}

func main() {
    fmt.Println("Hello Beego")
    beego.Router("/", &MainController{})
    beego.Router("/upload", &FileController{})
    beego.Run()
}


你可能感兴趣的:(golang)