一、config配置文件解析
go get github.com/astaxie/beego/config
1.首先初始化一个解析器对象

2.解析器对象支持的函数有如下:

3.解析器对象支持的函数有如下:
ini 配置文件支持 section 操作,key通过 section::key 的方式获取
例如下面这样的配置文件
[demo]
key1 = "asta"
key2 = "xie"
那么可以通过 iniconf.String("demo::key2") 获取值
二、httplib
httplib 库主要用来模拟客户端发送 HTTP 请求,类似于 Curl 工具,支持 JQuery 类似的链式操作。使用起来相当的方便;通过如下方式进行安装:


这样就可以把百度的内容爬下来
package controllers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/httplib"
)
type TestHttpLibController struct {
beego.Controller
}
func (c *TestHttpLibController) Get() {
req := httplib.Get("http://www.baidu.com")
str,err:=req.String()
if err!=nil{
panic(err)
}
c.Ctx.WriteString(str)
}
3.context


通过Input对象获取客户端参数
示例:

网友评论