部署自己的本地服务器。
找了个三方包项目:beego。看了下还不错。 上代码。。。。:
首先直接安装三方包,CMD下:go get github.com/astaxie/beego 安装成功后会在pkg下面生成对应的包。和上期安装自己写的包编译生成后的,是一样的
package main
import (
"github.com/astaxie/beego"
)
type MainController struct {
beego.Controller
}
func (this *MainController) Get() {
this.Ctx.WriteString("hi get request
")
this.Ctx.WriteString("i am trevor
")
this.Ctx.WriteString("this is my golang small project
")
this.Ctx.WriteString("Using beego
")
this.Ctx.WriteString("beego is used for rapid development of restful APIs,web apps and backend services in go
")
this.Ctx.WriteString("address:github.com/astaxie/beego
")
}
func (this *MainController) Post() {
this.Ctx.WriteString("hi post")
}
func main() {
beego.Router("/", &MainController{})
beego.Run()
}
利用三方包后,短短26行代码就可以直接在局域网内访问http://IP:8080/