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,7 +27,6 @@ import "github.com/gin-contrib/static"
See the [example](example) See the [example](example)
[embedmd]:# (_example/simple/example.go go)
```go ```go
package main package main
@ -49,6 +48,8 @@ func main() {
c.String(200, "test") c.String(200, "test")
}) })
// Listen and Server in 0.0.0.0:8080 // 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 package main
import ( import (
"log"
"net/http" "net/http"
"strings" "strings"
@ -18,7 +19,6 @@ func (b *binaryFileSystem) Open(name string) (http.File, error) {
} }
func (b *binaryFileSystem) Exists(prefix string, filepath string) bool { func (b *binaryFileSystem) Exists(prefix string, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) { if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
if _, err := b.fs.Open(p); err != nil { if _, err := b.fs.Open(p); err != nil {
return false return false
@ -47,5 +47,7 @@ func main() {
c.String(200, "test") c.String(200, "test")
}) })
// Listen and Server in 0.0.0.0:8080 // 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 package main
import ( import (
"log"
"github.com/gin-contrib/static" "github.com/gin-contrib/static"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -9,14 +11,16 @@ func main() {
r := gin.Default() r := gin.Default()
// if Allow DirectoryIndex // if Allow DirectoryIndex
//r.Use(static.Serve("/", static.LocalFile("/tmp", true))) // r.Use(static.Serve("/", static.LocalFile("/tmp", true)))
// set prefix // 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.Use(static.Serve("/", static.LocalFile("/tmp", false)))
r.GET("/ping", func(c *gin.Context) { r.GET("/ping", func(c *gin.Context) {
c.String(200, "test") c.String(200, "test")
}) })
// Listen and Server in 0.0.0.0:8080 // 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) t.Error(err)
} }
defer os.Remove(f.Name()) defer os.Remove(f.Name())
f.WriteString("Gin Web Framework") _, _ = f.WriteString("Gin Web Framework")
f.Close() f.Close()
dir, filename := filepath.Split(f.Name()) dir, filename := filepath.Split(f.Name())
@ -94,7 +94,7 @@ func TestIndex(t *testing.T) {
t.Error(err) t.Error(err)
} }
defer os.Remove(f.Name()) defer os.Remove(f.Name())
f.WriteString("index") _, _ = f.WriteString("index")
f.Close() f.Close()
dir, filename := filepath.Split(f.Name()) dir, filename := filepath.Split(f.Name())
@ -118,7 +118,7 @@ func TestListIndex(t *testing.T) {
t.Error(err) t.Error(err)
} }
defer os.Remove(f.Name()) defer os.Remove(f.Name())
f.WriteString("Gin Web Framework") _, _ = f.WriteString("Gin Web Framework")
f.Close() f.Close()
dir, filename := filepath.Split(f.Name()) dir, filename := filepath.Split(f.Name())