Skip to content

Commit

Permalink
Merge pull request #44 from yiGmMk/dev/embedfile
Browse files Browse the repository at this point in the history
refactor: 使用embed file
  • Loading branch information
wujunwei928 authored Aug 25, 2024
2 parents a033489 + 2b0fbec commit 949fc5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
.idea
.idea/
.fleet/
node_modules
.netlify
package.json
package-lock.json
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

import (
"context"
"embed"
"html/template"
"io/fs"
"log"
"net/http"
"os"
Expand All @@ -19,10 +22,18 @@ type HttpResponse struct {
Data interface{} `json:"data"`
}

//go:embed templates/*
var files embed.FS

func main() {
r := gin.Default()

r.LoadHTMLGlob("templates/*")
sub, err := fs.Sub(files, "templates")
if err != nil {
panic(err)
}
tmpl := template.Must(template.ParseFS(sub, "*.tmpl"))
r.SetHTMLTemplate(tmpl)
r.GET("/", func(c *gin.Context) {
c.HTML(200, "index.tmpl", gin.H{
"title": "github.com/wujunwei928/parse-video Demo",
Expand Down

0 comments on commit 949fc5c

Please sign in to comment.