Skip to content

Commit 9ae1c0d

Browse files
committed
feat: Implement embed folder and a better organisation
1 parent d45d9a3 commit 9ae1c0d

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

example/embed/data/server/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Hello Embed</h1>

example/embed/example.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"embed"
5+
"fmt"
6+
"net/http"
7+
8+
"github.com/gin-contrib/static"
9+
"github.com/gin-gonic/gin"
10+
)
11+
12+
//go:embed data
13+
var server embed.FS
14+
15+
func main() {
16+
r := gin.Default()
17+
r.Use(static.Serve("/", static.EmbedFolder(server, "data/server")))
18+
r.GET("/ping", func(c *gin.Context) {
19+
c.String(200, "test")
20+
})
21+
r.NoRoute(func(c *gin.Context) {
22+
fmt.Printf("%s doesn't exists, redirect on /\n", c.Request.URL.Path)
23+
c.Redirect(http.StatusMovedPermanently, "/")
24+
})
25+
// Listen and Server in 0.0.0.0:8080
26+
r.Run(":8080")
27+
}

static.go renamed to serve.go

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)