From 268e78866a37f484e100d3670fd0ef19f466df08 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 2 Oct 2021 21:08:24 +0800 Subject: [PATCH] chore: fix lint Signed-off-by: Bo-Yi Wu --- README.md | 29 +++++++++++++++-------------- _example/bindata/example.go | 6 ++++-- _example/simple/example.go | 10 +++++++--- static_test.go | 6 +++--- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 428d1e2..18972be 100644 --- a/README.md +++ b/README.md @@ -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) + } } ``` diff --git a/_example/bindata/example.go b/_example/bindata/example.go index 692e238..09bbf96 100644 --- a/_example/bindata/example.go +++ b/_example/bindata/example.go @@ -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) + } } diff --git a/_example/simple/example.go b/_example/simple/example.go index 2bbec7f..8571002 100644 --- a/_example/simple/example.go +++ b/_example/simple/example.go @@ -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) + } } diff --git a/static_test.go b/static_test.go index 6925005..1f61eaf 100644 --- a/static_test.go +++ b/static_test.go @@ -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())