chore: fix lint

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2021-10-02 21:08:24 +08:00
parent 95ad8995a1
commit 268e78866a
4 changed files with 29 additions and 22 deletions

View File

@ -27,28 +27,29 @@ import "github.com/gin-contrib/static"
See the [example](example)
[embedmd]:# (_example/simple/example.go go)
```go
package main
import (
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r := gin.Default()
// if Allow DirectoryIndex
//r.Use(static.Serve("/", static.LocalFile("/tmp", true)))
// set prefix
//r.Use(static.Serve("/static", static.LocalFile("/tmp", true)))
// if Allow DirectoryIndex
//r.Use(static.Serve("/", static.LocalFile("/tmp", true)))
// set prefix
//r.Use(static.Serve("/static", static.LocalFile("/tmp", true)))
r.Use(static.Serve("/", static.LocalFile("/tmp", false)))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "test")
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
r.Use(static.Serve("/", static.LocalFile("/tmp", false)))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "test")
})
// Listen and Server in 0.0.0.0:8080
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}
```

View File

@ -1,6 +1,7 @@
package main
import (
"log"
"net/http"
"strings"
@ -18,7 +19,6 @@ func (b *binaryFileSystem) Open(name string) (http.File, error) {
}
func (b *binaryFileSystem) Exists(prefix string, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
if _, err := b.fs.Open(p); err != nil {
return false
@ -47,5 +47,7 @@ func main() {
c.String(200, "test")
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}

View File

@ -1,6 +1,8 @@
package main
import (
"log"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
)
@ -9,14 +11,16 @@ func main() {
r := gin.Default()
// if Allow DirectoryIndex
//r.Use(static.Serve("/", static.LocalFile("/tmp", true)))
// r.Use(static.Serve("/", static.LocalFile("/tmp", true)))
// set prefix
//r.Use(static.Serve("/static", static.LocalFile("/tmp", true)))
// r.Use(static.Serve("/static", static.LocalFile("/tmp", true)))
r.Use(static.Serve("/", static.LocalFile("/tmp", false)))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "test")
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}

View File

@ -28,7 +28,7 @@ func TestEmptyDirectory(t *testing.T) {
t.Error(err)
}
defer os.Remove(f.Name())
f.WriteString("Gin Web Framework")
_, _ = f.WriteString("Gin Web Framework")
f.Close()
dir, filename := filepath.Split(f.Name())
@ -94,7 +94,7 @@ func TestIndex(t *testing.T) {
t.Error(err)
}
defer os.Remove(f.Name())
f.WriteString("index")
_, _ = f.WriteString("index")
f.Close()
dir, filename := filepath.Split(f.Name())
@ -118,7 +118,7 @@ func TestListIndex(t *testing.T) {
t.Error(err)
}
defer os.Remove(f.Name())
f.WriteString("Gin Web Framework")
_, _ = f.WriteString("Gin Web Framework")
f.Close()
dir, filename := filepath.Split(f.Name())