package main
import (
"embed"
"github.com/gin-gonic/gin"
"html/template"
"io/fs"
"net/http"
)
//使用go:embed static template定义静态文件目录和模板文件目录
//这里的//go:embed static template并不是注释的意思
//go:embed static template
var f embed.FS
func main() {
app := gin.Default()
//设置模板文件目录
temple := template.Must(template.New("x").ParseFS(f, "template/**/*"))
app.SetHTMLTemplate(temple)
//设置静态文件目录
fp, _ := fs.Sub(f, "static")
app.StaticFS("/static", http.FS(fp))
//GET请求,“/”
app.GET("/", func(c *gin.Context) {
c.HTML(200, "index/index", nil)
})
//GET请求,“/admin”
app.GET("/admin", func(c *gin.Context) {
c.HTML(200, "admin/index", nil)
})
//运行
_ = app.Run("127.0.0.1:80")
}
网站首页 > 开源技术 正文
猜你喜欢
- 2024-11-11 Golang Web编程,模板解析 if、else if、else语句
- 2024-11-11 Go语言Web编程,Request查询参数URL Query GET
- 2024-11-11 模玩资讯:千值练《机动机器人WeGo》第四弹 微型 MechatroWego 盒玩
- 2024-11-11 Go语言编程从入门到精通(字符串创建、拼接、转换、替换、查找)
- 2024-11-11 Golang Web编程,array数组、Slice切片、Map集合、Struct结构体
- 2024-11-11 Go语言编程从入门到精通,方法和接口
- 2024-07-25 Go语言编程从入门到精通,数据类型:布尔、数值、浮点、字符串
- 2024-07-25 Go语言编程从入门到精通(通道、缓冲通道、阻塞、控制、select)
- 2024-07-25 Go语言编程从入门到精通,流程控制之switch、for、defer
- 2024-07-25 Golang并发编程,4、无缓冲通道和有缓冲通道的区别
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- jdk (81)
- putty (66)
- rufus (78)
- 内网穿透 (89)
- okhttp (70)
- powertoys (74)
- windowsterminal (81)
- netcat (65)
- ghostscript (65)
- veracrypt (65)
- asp.netcore (70)
- wrk (67)
- aspose.words (80)
- itk (80)
- ajaxfileupload.js (66)
- sqlhelper (67)
- express.js (67)
- phpmailer (67)
- xjar (70)
- redisclient (78)
- wakeonlan (66)
- tinygo (85)
- startbbs (72)
- webftp (82)
- vsvim (79)
本文暂时没有评论,来添加一个吧(●'◡'●)