doc: Update use embedmd (include file in .md)

This commit is contained in:
Valentin Omnès 2021-03-15 23:30:19 +01:00
parent ebb0d398c3
commit 5d1b16d05b
2 changed files with 7 additions and 7 deletions

View File

@ -11,7 +11,7 @@ install:
- go get github.com/campoy/embedmd - go get github.com/campoy/embedmd
script: script:
- embedmd -d *.md - embedmd -w *.md
- go test -v -covermode=atomic -coverprofile=coverage.out - go test -v -covermode=atomic -coverprofile=coverage.out
after_success: after_success:

View File

@ -27,9 +27,8 @@ import "github.com/gin-contrib/static"
See the [example](example) See the [example](example)
[embedmd]:# (example/simple/example.go go)
#### Serve local file #### Serve local file
[embedmd]:# (example/simple/example.go)
```go ```go
package main package main
@ -56,6 +55,7 @@ func main() {
``` ```
#### Serve embed folder #### Serve embed folder
[embedmd]:# (example/embed/example.go)
```go ```go
package main package main
@ -68,16 +68,16 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
//go:embed tmp/server //go:embed data
var server embed.FS var server embed.FS
func main() { func main() {
r := gin.Default() r := gin.Default()
r.Use(static.Serve("/", static.EmbedFolder(server, "tmp/server"))) r.Use(static.Serve("/", static.EmbedFolder(server, "data/server")))
r.GET("/ping", func(c *gin.Context) { r.GET("/ping", func(c *gin.Context) {
c.String(200, "test") c.String(200, "test")
}) })
r.NoRoute(func (c *gin.Context) { r.NoRoute(func(c *gin.Context) {
fmt.Printf("%s doesn't exists, redirect on /\n", c.Request.URL.Path) fmt.Printf("%s doesn't exists, redirect on /\n", c.Request.URL.Path)
c.Redirect(http.StatusMovedPermanently, "/") c.Redirect(http.StatusMovedPermanently, "/")
}) })