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的更多相关文章
随机推荐
- 【URAL 1989】 Subpalindromes(线段树维护哈希)
Description You have a string and queries of two types: replace i'th character of the string by char ...
- SQL练习题笔记
查找最晚入职员工的所有信息 select * from employees order by hire_date desc limit 1 查找入职员工时间排名倒数第三的员工所有信息 select * ...
- springMVC中处理静态资源的几种方案
处理静态资源方案一:在web.xml文件中配置如下: <!-- <!–解决静态资源方案–> <servlet-mapping> <servlet-name>d ...
- RF新手常见问题总结--(基础篇)
1. 经常有人问这个元素找不到,一般先排除这两个地方,再自己找找A:是否等待了足够的时间让元素加载 (增加sleep xx, wait Until xxx)B: 仔细查查,这个元素是否进入到另一个f ...
- python +selenium 自带case +生成报告的模板
https://github.com/huahuijay/python-selenium2这个就是 python +selenium的 里面还自带case 然后也有生成报告的模板 我的: https: ...
- python004 Python3 解释器
Python3 解释器Linux/Unix的系统上,一般默认的 python 版本为 2.x,我们可以将 python3.x 安装在 /usr/local/python3 目录中.安装完成后,我们可以 ...
- 【bzoj1042】[HAOI2008]硬币购物-递推与动规-容斥原理
硬币购物 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买si的价值的东西.请问每次有多少种付款方法. Input 第一行 c1,c2 ...
- mysql免安装版配置使用
mysql免安装版配置使用 1.下载解压 2.配置环境变量 变量MYSQL_HOME = 解压目录 配置变量path 编辑,在后面加上 ;%MYSQL_HOME%\bin 3.修改配置文件 增加或 ...
- 使用windows操作EXCEL如何关闭EXCEL进程
经常项目上有导入excel的需求,其实导入一个固定格式的excel数据非常容易,但是,发现一个问题就是,导入excel后,用户在打开excel时,必须要打开2次才能打开excel,这让人很不爽:开始查 ...
- Linux虚拟机fdisk分区
以下操作全部基于win7 64位系统上的Linux虚拟机(CentOS6.6). 当Linux虚拟机的硬盘空间不够用时,可以手动添加硬盘块,流程如下: 右键虚拟机,点击“Add”按钮: 选择“Hard ...