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 111c2d589e
commit d361912309
No known key found for this signature in database
4 changed files with 19 additions and 7 deletions

View File

@ -27,8 +27,11 @@ import "github.com/gin-contrib/static"
See the [example](example)
<<<<<<< HEAD
#### Serve local file
=======
>>>>>>> 268e788 (chore: fix lint)
```go
package main
@ -83,5 +86,8 @@ func main() {
})
// 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,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())