Skip to content

Commit

Permalink
feat: Implement embed folder and a better organisation
Browse files Browse the repository at this point in the history
  • Loading branch information
vomnes committed Mar 15, 2021
1 parent d45d9a3 commit 9ae1c0d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/embed/data/server/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello Embed</h1>
27 changes: 27 additions & 0 deletions example/embed/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"embed"
"fmt"
"net/http"

"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
)

//go:embed data
var server embed.FS

func main() {
r := gin.Default()
r.Use(static.Serve("/", static.EmbedFolder(server, "data/server")))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "test")
})
r.NoRoute(func(c *gin.Context) {
fmt.Printf("%s doesn't exists, redirect on /\n", c.Request.URL.Path)
c.Redirect(http.StatusMovedPermanently, "/")
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
}
File renamed without changes.
File renamed without changes.

0 comments on commit 9ae1c0d

Please sign in to comment.