goweb(http)-项目

本文介绍了在GoWeb项目中如何进行会话控制,重点讨论了session的概念和重要性。通过创建user和books表展示了数据库的准备工作。会话控制用于解决HTTP协议无状态的问题,通过cookie在服务器和浏览器间保存用户状态。文章详细讲解了cookie的创建、有效期设置及其应用场景,并提及session数据通常存储在数据库中,如carts和orders表。最后提到了管理cookie和session的策略,如定期清理缓存和禁用cookie。
摘要由CSDN通过智能技术生成

在这里插入图片描述
main.go

package main

import (
	"net/http"
	"text/template"
)

// 处理器函数
func ServerHttp(w http.ResponseWriter,r *http.Request){
   
	t := template.Must(template.ParseFiles("view/index.html"))
	t.Execute(w,nil)
}

func main(){
   
	http.Handle("/css/",http.StripPrefix("/css/",http.FileServer(http.Dir("view/css"))))
	http.Handle("/js/",http.StripPrefix("/js/",http.FileServer(http.Dir("view/js"))))
	http.Handle("/images/",http.StripPrefix("/images/",http.FileServer(http.Dir("view/images"))))
	http.Handle("/fonts/",http.StripPrefix("/fonts/",http.FileServer(http.Dir("view/fonts"))))
	http.HandleFunc("/",ServerHttp)
	http.ListenAndServe(":8080",nil)
}

db.go

package utils

import (
	"fmt"
	"database/sql"
	_"mysql-master"
)

var 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值