本文整理匯總了Golang中ibookings/utils.Cookie類的典型用法代碼示例。如果您正苦於以下問題:Golang Cookie類的具體用法?Golang Cookie怎麽用?Golang Cookie使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Cookie類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Exit
func (this *LoginController) Exit() {
r := this.Request
w := this.ResponseWriter
cookie := u.Cookie{HTTP: this.HTTP}
cookie.DestroyCooike()
http.Redirect(w, r, "/", http.StatusSeeOther)
}
示例2: Edit
func (this *UserController) Edit() {
w := this.ResponseWriter
r := this.Request
data := e.TData{}
common := CommonController{HTTP: this.HTTP}
t := common.getTpl("User.edit.introduction.tpl", "User.edit.tpl", "User.edit.avatar.tpl", "User.edit.baseinfo.tpl", "User.edit.skills.tpl", "User.edit.skill.tpl", "User.edit.introduction.tpl")
r.ParseForm()
userId := r.FormValue("id")
user := m.User{Id: userId}
cookie := u.Cookie{HTTP: this.HTTP}
cookie = cookie.GetCookie()
flag := true
if cookie.UserId == nil || userId != cookie.UserId.Value { //無登錄cookie
flag = false
}
if flag {
user = user.GetOneUserById()
data.CurrentUser = user
data.Data = user
data.Flag = flag
t.Execute(w, &data)
} else {
Error{HTTP: this.HTTP}.Get()
}
}
示例3: Q
func (this *UserController) Q() {
w := this.ResponseWriter
r := this.Request
r.ParseForm()
parId := r.FormValue("id")
common := CommonController{HTTP: this.HTTP}
t := common.getTpl("UserDetail", "T.user.tpl", "Order.add.tpl")
showuser := m.User{Id: parId}
data := e.TData{}
flag := false
isCurrentUser := false
cookie := u.Cookie{HTTP: this.HTTP}
cookie = cookie.GetCookie()
// log.Println("獲取cookie中的用戶名")
// username := u.GetCookieUserName(w, r)
// if username != "" { //如果已經登錄了
// user = user.GetOneUserByName(username)
// } else {
// }
log.Println(parId)
if parId == "" {
log.Println("url有錯誤")
}
showuser = showuser.GetOneUserById()
loginuser := m.User{}
userId := cookie.UserId //登錄用戶
log.Println(showuser.RealName)
if showuser.RealName != "" { //查到用戶
if userId != nil { //查到有登錄用戶
loginuser.Id = userId.Value
flag = true
if showuser.Id == loginuser.Id { //已登錄的用戶瀏覽別人的資料
isCurrentUser = true
}
}
if !isCurrentUser { //別人瀏覽
telph := u.SubString(showuser.UserName, 0, len(showuser.UserName)-4) + "****"
idCard := u.SubString(showuser.IDCard, 0, len(showuser.IDCard)-4) + "****"
showuser.UserName = telph
showuser.IDCard = idCard
}
data = e.TData{Data: showuser, CurrentUser: loginuser, Flag: flag}
t.Execute(w, &data)
}
}
示例4: Check
func (this *LoginController) Check() {
data := e.Data{Status: 1, Msg: "已登錄"}
cookie := u.Cookie{HTTP: this.HTTP}
cookie = cookie.GetCookie()
if cookie.UserId == nil { //沒有登錄
data.Status = 0
data.Msg = "沒有登錄"
data.Data = "/login"
}
u.OutputJson(this.ResponseWriter, &data)
}
示例5: Post
func (this *AvatarController) Post() {
w := this.ResponseWriter
r := this.Request
data := e.Data{Status: 1, Msg: "上傳成功"}
log.Println("頭像上傳post")
r.ParseMultipartForm(32 << 20)
log.Println("表單解析")
file, handler, err := r.FormFile("realPicFile")
if err != nil {
log.Println("上傳錯誤")
return
}
fileext := filepath.Ext(handler.Filename)
log.Println("文件後綴名字" + fileext)
if u.Check(fileext) == false {
data.Status = 0
data.Msg = "不允許的上傳類型"
u.OutputJson(w, &data)
return
}
cookie := u.Cookie{HTTP: this.HTTP}
filename := cookie.GetCookie().UserId.Value + ".png"
log.Println("文件名稱" + filename)
imgfile, _ := os.OpenFile(Upload_Dir+filename, os.O_CREATE|os.O_WRONLY, 0660)
defer imgfile.Close()
//把圖片變成400X400尺寸的
m1, err := jpeg.Decode(file)
if err != nil {
panic(err)
}
bounds := m1.Bounds()
//如果第二參數為0則保持橫縱比
g := gift.New(
gift.Resize(400, 400, gift.LanczosResampling),
)
dst := image.NewRGBA(g.Bounds(bounds))
g.Draw(dst, m1)
err = png.Encode(imgfile, dst)
if err != nil {
log.Println("上傳失敗")
return
}
filedir := Show_Dir + filename
data.Data = filedir
log.Println(data)
u.OutputJson(w, &data)
}
示例6: Info
func (this *AccountController) Info() {
w := this.ResponseWriter
r := this.Request
r.ParseForm()
parId := r.FormValue("id")
common := CommonController{HTTP: this.HTTP}
t := common.getTpl("account", "Account.info.tpl")
showuser := m.User{Id: parId}
data := e.TData{}
flag := false
cookie := u.Cookie{HTTP: this.HTTP}
cookie = cookie.GetCookie()
// log.Println("獲取cookie中的用戶名")
// username := u.GetCookieUserName(w, r)
// if username != "" { //如果已經登錄了
// user = user.GetOneUserByName(username)
// } else {
// }
log.Println(parId)
if parId == "" {
log.Println("url有錯誤")
}
showuser = showuser.GetOneUserById()
loginuser := m.User{}
log.Println(showuser.ABalance, showuser.FBalance)
userId := cookie.UserId //登錄用戶
log.Println(showuser.RealName)
if showuser.RealName != "" { //查到用戶
if userId != nil { //查到有登錄用戶
loginuser.Id = userId.Value
flag = true
if showuser.Id == loginuser.Id { //自己瀏覽自己
data = e.TData{Data: showuser, CurrentUser: loginuser, Flag: flag}
t.Execute(w, &data)
}
}
}
}
示例7: ShowPage
func (this *CommonController) ShowPage(choose string, views ...string) {
wr := this.ResponseWriter
t := u.ParesFiles(views...)
cookie := u.Cookie{HTTP: this.HTTP}
cookie = cookie.GetCookie()
user := m.User{}
flag := false
log.Println("登錄cookie獲取", cookie)
if cookie.UserId != nil {
user.Id = cookie.UserId.Value
flag = true
}
var data e.TData = e.TData{CurrentUser: user, Flag: flag, Selected: choose}
log.Println("data", data)
t.Execute(wr, &data)
}
示例8: Add
func (this *OrderController) Add() {
w := this.ResponseWriter
r := this.Request
data := e.Data{Msg: "生成訂單成功", Status: 1}
r.ParseForm()
money := r.FormValue("money")
startTime := r.FormValue("startTime")
endTime := r.FormValue("endTime")
address := r.FormValue("address")
ruserId := r.FormValue("ruser")
remark := r.FormValue("remark")
skillId := r.FormValue("skill")
order := m.Order{}
order.Skill.Id = skillId
order.Skill = order.Skill.GetSkillById()
order.RUser = ruserId
cookie := u.Cookie{HTTP: this.HTTP}
cookie = cookie.GetCookie()
if cookie.UserId != nil {
order.OUser = cookie.UserId.Value
}
log.Println(startTime)
log.Println(endTime)
order.BeginTime, _ = time.Parse("2006-01-02 15:04", startTime)
order.EndTime, _ = time.Parse("2006-01-02 15:04", endTime)
order.OrderTime = time.Now()
order.Status = "預約"
order.Remark = remark
order.Address = address
order.TotalPrice, _ = strconv.ParseFloat(money, 32)
ordered, err := order.InsertOrder()
data.Data = ordered
if err != nil {
data.Msg = "訂單生成失敗"
data.Status = 0
}
u.OutputJson(w, &data)
}
示例9: Get
func (this *OrderController) Get() {
w := this.ResponseWriter
r := this.Request
skill := r.FormValue("skill")
// common := CommonController{HTTP: this.HTTP}
// common.ShowPage("", "Order.add.tpl")
cookie := u.Cookie{HTTP: this.HTTP}
cookie = cookie.GetCookie()
log.Println(cookie.UserId)
if cookie.UserId == nil { //沒有登錄,則跳轉到登錄界麵
http.Redirect(w, r, "/login", http.StatusSeeOther)
} else {
t, err := t.ParseFiles("views/Order.add.tpl")
if err != nil {
log.Println(err)
}
t.ExecuteTemplate(w, "orderAdd", skill)
}
}
示例10: Cut
func (this *AvatarController) Cut() {
r := this.Request
data := e.Data{Status: 1, Msg: "上傳成功"}
r.ParseForm()
x, err := strconv.Atoi(r.FormValue("x"))
y, err := strconv.Atoi(r.FormValue("y"))
x2, err := strconv.Atoi(r.FormValue("x2"))
y2, err := strconv.Atoi(r.FormValue("y2"))
fileName := r.FormValue("fileName")
log.Println(x, y, x2, y2, fileName)
g := gift.New(
gift.Crop(image.Rect(x, y, x2, y2)),
gift.Resize(220, 220, gift.LanczosResampling),
)
log.Println("圖片名稱" + fileName)
//打開待處理的圖片
file, err := os.Open(fileName)
if err != nil {
panic(err)
}
defer file.Close()
m1, err := png.Decode(file)
if err != nil {
panic(err)
}
bounds := m1.Bounds()
dst := image.NewRGBA(g.Bounds(bounds))
g.Draw(dst, m1)
cookie := u.Cookie{HTTP: this.HTTP}
filename := cookie.GetCookie().UserId.Value + ".png"
imgfile, err := os.Create(Avatar_ReDir + filename)
os.Remove(Upload_Dir + filename)
defer imgfile.Close()
err = png.Encode(imgfile, dst)
u.OutputJson(this.ResponseWriter, &data)
}
示例11: dispatchController
func dispatchController(w http.ResponseWriter, r *http.Request) {
web := e.HTTP{Request: r, ResponseWriter: w}
// defer func() {
// log.Println("defer func is run")
// e := recover()
// if r != nil {
// log.Println("recover : ", e)
// }
// }()
pathInfo := strings.Trim(r.URL.Path, "/")
parts := strings.Split(pathInfo, "/")
r.ParseForm()
cookie := u.Cookie{HTTP: web}
cookie.InitCooike()
log.Println((parts))
if parts[0] != "" {
log.Println("檢測到url後麵帶/")
var controllerName = ""
var methodName = ""
var formKey = ""
var formValue = ""
//處理類似URLxxx.com/login/exit/u/[email protected]
for index, value := range parts {
switch index {
case 0:
//類名字
controllerName = value
case 1:
//方法名字
methodName = strings.Title(value)
default:
if index%2 == 0 {
formKey = value
} else {
formValue = value
}
if formKey != "" && formValue != "" {
log.Println("表單Key" + formKey)
log.Println("表單Value" + formValue)
r.Form.Add(formKey, formValue)
//r.Form.Add("1", "1")
log.Println(r.Form)
formKey = ""
formValue = ""
}
}
}
log.Println("controllerName:", controllerName)
log.Println("methodName:", methodName)
controllerClass, ok := Cotrollers[controllerName]
if !ok {
log.Print("沒有找到Controller:", controllerName)
controllerClass = Error{}
}
controller := reflect.ValueOf(controllerClass)
if methodName == "" {
if r.Method == "GET" {
methodName = "Get"
} else if r.Method == "POST" {
methodName = "Post"
}
}
method := controller.MethodByName(methodName)
if method.IsValid() {
// requestValue := reflect.ValueOf(r)
// responseValue := reflect.ValueOf(w)
log.Println(controller)
webValue := reflect.ValueOf(web)
httpField := controller.Elem().FieldByName("HTTP")
log.Println("httpField", httpField, httpField.CanSet())
httpField.Set(webValue)
// fieldElem := httpField.Elem()
// log.Println("Field can Set", fieldElem.CanSet())
// fieldElem.Set(webValue)
// responseWriter := controller.FieldByName("ResponseWriter")
// responseWriter.Set(responseWriter)
//method.Call([]reflect.Value{responseValue, requestValue})
method.Call(nil)
} else {
log.Print("沒有找到Method:", methodName)
}
} else {
index := IndexController{HTTP: web}
index.Index()
}
}