从0开始学golang--1--部署本地服务器

部署自己的本地服务器。

找了个三方包项目: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\n")
    this.Ctx.WriteString("i am trevor\n")
    this.Ctx.WriteString("this is my golang small project\n")
    this.Ctx.WriteString("Using beego\n")
    this.Ctx.WriteString("beego is used for rapid development of restful APIs,web apps and backend services in go\n")
    this.Ctx.WriteString("address:github.com/astaxie/beego\n")
}
func (this *MainController) Post() {
    this.Ctx.WriteString("hi post")
}
func main() {
    beego.Router("/", &MainController{})
    beego.Run()
}
 
利用三方包后,短短26行代码就可以直接在局域网内访问 http://IP:8080/

猜你喜欢

转载自www.cnblogs.com/Liang2790912648/p/10604055.html
今日推荐