beego6
package main //beego使用的是go语言原生的模版 import (
//_ "beego1/routers" //默认controll文件夹里面的控制器
"github.com/astaxie/beego"
//"strconv"
) type HomeController struct {
beego.Controller
} func (this *HomeController) Get() {
this.Ctx.WriteString("appname::::::" + beego.AppConfig.String("appname") +
"\nhttpport" + beego.AppConfig.String("httpport") +
"\nrunmode:" + beego.AppConfig.String("runmode")) //读取的是conf里面的app.conf文件里面的内容 // hp := strconv.Itoa(beego.HttpPort)
// this.Ctx.WriteString("appname:" + beego.AppName +
// "\nhttpport" + hp +
// "\nrunmode:" + beego.RunMode) //读取的是conf里面的app.conf文件里面的内容 //打印
beego.Trace("trace")
beego.Info("info")
beego.Debug("debug")
beego.Warn("warn")
beego.Error("error") } func main() {
beego.Router("/", &HomeController{})
beego.Run()
}
go原生读取cookie
package main import (
"io"
"net/http"
"strings"
) func mian() {
http.HandleFunc("/", cookie)
http.ListenAndServe(":8080", nil)
} func cookie1(w http.ResponseWriter, r *http.Request) {
ck := &http.Cookie{
Name: "mycookie",
Value: "hello",
Path: "/", //路径根目录
Domain: "localhosst", //域名
MaxAge: 120,
}
http.SetCookie(w, ck) //设置cookie,ck是cookie
ck2, err := r.Cookie("mycookie") //读取cookie
if err != nil {
io.WriteString(w, err.Error())
return
}
io.WriteString(w, ck2.Value)
} func cookie(w http.ResponseWriter, r *http.Request) {
ck := &http.Cookie{
Name: "mycookie",
Value: "hellowwww",
Path: "/", //路径根目录
Domain: "localhosst", //域名
MaxAge: 120,
}
w.Header().Set("Set-Cookie", ck.String()) //通过Header设置cookie
w.Header().Set("Set-Cookie", strings.Replace(ck.String(), " ", "%20", -1)) //除去空格
ck2, err := r.Cookie("mycookie") //读取cookie
if err != nil {
io.WriteString(w, err.Error())
return
}
io.WriteString(w, ck2.Value)
}
go原生解析表单 package main //直接使用go模仿beego解析表单,在src下建立一个文件夹test,
//test里面就放一个main.go。通过git Bash进入到该目录,
//go run main.go
import (
"fmt"
//"io"
"html/template"
"net/http"
) func main() {
http.HandleFunc("/", Hey)
http.ListenAndServe(":8080", nil)
} const tpl = `
<html>
<head>
<title>hey</title>
</head>
<body>
<form method="POST" action="/">
name: <input name="name" id="name"/>
pwd: <input name="pwd" id="pwd"/>
<input type="submit">ok</input>
</form>
</body>
</html>
` func Hey(w http.ResponseWriter, r *http.Request) {
//前面不加*号是接口,后面加*号是struct,要传地址,
//只有这种签名的函数才能够注册为handler
// fmt.Println("llllll")
// io.WriteString("ssssssssfffffff)
if r.Method == "GET" { //get请求的时候返回html
t := template.New("hey")
t.Parse(tpl)
t.Execute(w, nil)
} else { //post请求的时候解析form
fmt.Println(r.FormValue("name"))
}
}
beego6的更多相关文章
随机推荐
- 基于 WPF + Modern UI 的 公司OA小助手 开发总结
前言: 距离上一篇博客,整整一个月的时间了.人不能懒下来,必须有个阶段性的总结,算是对我这个阶段的一个反思.人只有在总结的过程中才会发现自己的不足. 公司每天都要在OA系统上上班点击签到,下班点击签退 ...
- Linux 下Python2.7解决list打印中文字符问题
在写一个爬取智联招聘数据的爬虫中,将所需内容匹配到后打印出现了utf-8字符,并没有出现中文字符. 例如: >>>listnine = ['梨', '橘子', '苹果', '香蕉'] ...
- XV6环境搭建及注意事项
Ubuntu16.04SLT 64位 工具链 sudo apt-get install gcc-multilib libsdl1.2-dev, libtool-bin, libglib2.0-dev, ...
- windows 环境下.Net使用Redis缓存
Redis简介 Redis是一个开源的,使用C语言编写,面向“键/值”对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景.Redis纯粹为应用而产生,它是一个高性能的 ...
- .NET下 JSON 的一些常用操作
1.JSON的序列化和反序列化 Newtonsoft.Json dll 下载地址http://json.codeplex.com/ using System; using System.Collect ...
- POJ 1523 网络连通
题目大意: 给你一个网络组,每台机子与其他机子的关系,让你找到所有的割点,如果没有割点,输出无 这道题目就是最直接的求割点问题,我在这里用的是邻接矩阵来存储机子之间的关系 割点问题的求解需要对深度优先 ...
- ubuntu使用git的时:Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts.
1:问题现象: hlp@hlp:~/code/github_code/catch_imooc1$ git push origin master Warning: Permanently added t ...
- Linux(4):文件属性
文件属性: # 重点: 磁盘空间不足 和 软链接与硬链接的区别 查看文件的属性: # ls lhi 文件 [root@NEO ~]# ls -lhi /etc/hosts 130078 -rw-r-- ...
- CodeForces - 586D Phillip and Trains
这道题是一道搜索题 但是 如果没有读懂或者 或者拐过弯 就很麻烦 最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错 利用相对运动 计周期为 人 ...
- google play上获取apk文件
先说一种测试不通过的方法(chrome浏览器添加Direct APK downloader拓展程序),浪费了我很多的时间,结果发现根本用不了,记录一下过程给大家参考. 使用chrome浏览器,点击左上 ...