摘要: 一,代码: package main import ( "embed" "flag" "github.com/gofiber/template/html/v2" "net/http" "fmt" "runtime" "industry/config" "industry/routes" ) // 构 阅读全文
posted @ 2024-11-23 10:43 刘宏缔的架构森林 阅读(65) 评论(0) 推荐(0)
摘要: 一,官方网站: https://gorm.io/ 如图: 二,安装: 从命令行安装gorm $ go get -u gorm.io/gorm go: downloading gorm.io/gorm v1.25.12 go: downloading github.com/jinzhu/now v1. 阅读全文
posted @ 2024-11-23 09:18 刘宏缔的架构森林 阅读(247) 评论(0) 推荐(0)
摘要: 一,代码 1,模块 package page import "fmt" type Page struct { //定义分页的struct Total int `json:"total"` TotalPage int `json:"totalpage"` CurrentPage int `json:" 阅读全文
posted @ 2024-11-23 09:17 刘宏缔的架构森林 阅读(46) 评论(0) 推荐(0)
摘要: 一,代码 func main() { app := fiber.New() app.Static("/", "./public") // => http://localhost:3000/js/script.js // => http://localhost:3000/css/style.css a 阅读全文
posted @ 2024-11-23 09:15 刘宏缔的架构森林 阅读(66) 评论(0) 推荐(0)
摘要: 一,代码: 官网文档地址: https://docs.gofiber.io/api/middleware/session 1,全局变量 package config import ( "github.com/gofiber/fiber/v2/middleware/session" "github.c 阅读全文
posted @ 2024-11-23 09:06 刘宏缔的架构森林 阅读(55) 评论(0) 推荐(0)
摘要: 一,代码 说明: 1,中文字符串的长度: golang中string底层是通过byte数组实现的,所以直接求len,实际是在按字节长度计算。中文字符在unicode下占2个字节,在utf-8编码下占3个字节,而golang默认编码正好是utf-8。所以一个汉字占3个字节算了3个长度。所以打印长度为8 阅读全文
posted @ 2024-11-23 09:05 刘宏缔的架构森林 阅读(351) 评论(0) 推荐(0)
摘要: 一,现象: $ ./industry 2024/11/21 10:32:19.288954 app.go:999: [Warn] failed to load views: lstat ./views: no such file or directory 二进制文件启动时会报错找不到views目录 阅读全文
posted @ 2024-11-23 09:05 刘宏缔的架构森林 阅读(62) 评论(0) 推荐(0)