diff --git a/CNAME b/.github/CNAME similarity index 100% rename from CNAME rename to .github/CNAME diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 3496e36f..be6ceca7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -18,7 +18,10 @@ assignees: "" ```go package main -func main() { +import "github.com/gofiber/fiber" +func main() { + app := fiber.New() + // .. } ``` diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index 655c8509..3fc97ff5 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -12,7 +12,10 @@ assignees: "" ```go package main -func main() { +import "github.com/gofiber/fiber" +func main() { + app := fiber.New() + // .. } ``` diff --git a/LICENSE b/.github/LICENSE similarity index 100% rename from LICENSE rename to .github/LICENSE diff --git a/README.md b/.github/README.md similarity index 96% rename from README.md rename to .github/README.md index 1004f1e4..25d84588 100644 --- a/README.md +++ b/.github/README.md @@ -243,7 +243,20 @@ If you want to say **thank you** and/or support the active development of `fiber Buy Me A Coffee -### ⭐️ Stars +## ☕ Supporters + + + + + +
+ +
+ ToishY +
+
+ +## ⭐️ Stars Stars over time diff --git a/.github/README_de.md b/.github/README_de.md index e10974e1..0fc2ca29 100644 --- a/.github/README_de.md +++ b/.github/README_de.md @@ -243,7 +243,20 @@ Falls du **danke** sagen möchtest und/oder aktiv die Entwicklung von `fiber` f Buy Me A Coffee -### ⭐️ Sterne +## ☕ Supporters + + + + + +
+ +
+ ToishY +
+
+ +## ⭐️ Sterne Stars over time diff --git a/.github/README_es.md b/.github/README_es.md index 40a5c1ad..ea579fdb 100644 --- a/.github/README_es.md +++ b/.github/README_es.md @@ -242,7 +242,20 @@ Si quiere **agradecer** y / o apoyar el desarrollo activo de la `fiber` : Buy Me A Coffee -### ⭐️ estrellas +## ☕ Supporters + + + + + +
+ +
+ ToishY +
+
+ +## ⭐️ estrellas Stars over time diff --git a/.github/README_ja.md b/.github/README_ja.md index 1ccb5fbb..0a6764f2 100644 --- a/.github/README_ja.md +++ b/.github/README_ja.md @@ -242,7 +242,20 @@ func main() { Buy Me A Coffee -### ⭐️ スター +## ☕ Supporters + + + + + +
+ +
+ ToishY +
+
+ +## ⭐️ スター Stars over time diff --git a/.github/README_ko.md b/.github/README_ko.md index 1cb26b11..7f729639 100644 --- a/.github/README_ko.md +++ b/.github/README_ko.md @@ -243,7 +243,20 @@ func main() { Buy Me A Coffee -### ⭐️ Stars +## ☕ Supporters + + + + + +
+ +
+ ToishY +
+
+ +## ⭐️ Stars Stars over time diff --git a/.github/README_pt.md b/.github/README_pt.md index 6f1be54b..3a97c2f7 100644 --- a/.github/README_pt.md +++ b/.github/README_pt.md @@ -243,7 +243,20 @@ Se você quer **agradecer** e/ou apoiar o desenvolvimento ativo do `fiber` : Buy Me A Coffee -### ⭐️ Estrelas +## ☕ Supporters + + + + + +
+ +
+ ToishY +
+
+ +## ⭐️ Estrelas Stars over time diff --git a/.github/README_ru.md b/.github/README_ru.md index a1cf7995..674abaeb 100644 --- a/.github/README_ru.md +++ b/.github/README_ru.md @@ -242,7 +242,20 @@ func main() { Buy Me A Coffee -### ⭐️ Звезды +## ☕ Supporters + + + + + +
+ +
+ ToishY +
+
+ +## ⭐️ Звезды Stars over time diff --git a/.travis.yml b/.travis.yml index c087959d..8e6154cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,4 +12,4 @@ install: - go get -v golang.org/x/lint/golint script: # - golint -set_exit_status ./... - - go test -race ./... + - go test ./... diff --git a/application.go b/application.go index fc3186f4..e1b8ea21 100644 --- a/application.go +++ b/application.go @@ -29,8 +29,10 @@ import ( ) const ( - // Version : Fiber version - Version = "1.4.3" + // Version : Fiber release + Version = "1.4.4" + // Website : Fiber documentation + Website = "https://fiber.wiki" banner = "\x1b[1;32m" + ` ______ __ ______ ______ ______ /\ ___\ /\ \ /\ == \ /\ ___\ /\ == \ \ \ __\ \ \ \ \ \ __< \ \ __\ \ \ __< @@ -48,7 +50,8 @@ var ( // Application structure type Application struct { // Server name header - Server string + Server string + // HTTP server struct httpServer *fasthttp.Server // Show fiber banner Banner bool @@ -56,7 +59,8 @@ type Application struct { Engine *engine // https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/ Prefork bool - child bool + // is child process + child bool // Stores all routes routes []*Route } @@ -274,6 +278,7 @@ func (app *Application) Static(args ...string) { prefix := "/" root := "./" wildcard := false + midware := false // enable / disable gzipping somewhere? // todo v2.0.0 gzip := true @@ -293,11 +298,9 @@ func (app *Application) Static(args ...string) { // app.Static("/*", "./public/index.html") if prefix == "*" || prefix == "/*" { wildcard = true - } - - // Check if root exists - if _, err := os.Lstat(root); err != nil { - log.Fatal("Static: ", err) + } else if strings.Contains(prefix, "*") { + prefix = strings.Replace(prefix, "*", "", -1) + midware = true } // Lets get all files from root @@ -321,22 +324,18 @@ func (app *Application) Static(args ...string) { path := filepath.Join(prefix, strings.Replace(file, mount, "", 1)) // for windows: static\index.html => /index.html path = filepath.ToSlash(path) - // Store absolute file path to use in ctx handler - var filePath string - var err error - if filePath, err = filepath.Abs(file); err != nil { - log.Fatal("Static: ", err) - } + // Store file path to use in ctx handler + filePath := file // If the file is an index.html, bind the prefix to index.html directly if filepath.Base(filePath) == "index.html" || filepath.Base(filePath) == "index.htm" { - app.routes = append(app.routes, &Route{"GET", prefix, wildcard, false, nil, nil, func(c *Ctx) { + app.routes = append(app.routes, &Route{"GET", prefix, midware, wildcard, nil, nil, func(c *Ctx) { c.SendFile(filePath, gzip) }}) } // Add the route + SendFile(filepath) to routes - app.routes = append(app.routes, &Route{"GET", path, wildcard, false, nil, nil, func(c *Ctx) { + app.routes = append(app.routes, &Route{"GET", path, midware, wildcard, nil, nil, func(c *Ctx) { c.SendFile(filePath, gzip) }}) } @@ -426,7 +425,7 @@ func (app *Application) Test(req *http.Request) (*http.Response, error) { return nil, err } // Throw timeout error after 200ms - case <-time.After(500 * time.Millisecond): + case <-time.After(1000 * time.Millisecond): return nil, fmt.Errorf("timeout") } // Get raw HTTP response diff --git a/application_test.go b/application_test.go index ff978c54..acc83ce1 100644 --- a/application_test.go +++ b/application_test.go @@ -45,9 +45,10 @@ func Test_Methods(t *testing.T) { func Test_Static(t *testing.T) { app := New() + + app.Static("/yesyes*", ".github/FUNDING.yml") app.Static("./.github") app.Static("/john", "./.github") - app.Static("*", "./.github/stale.yml") req, _ := http.NewRequest("GET", "/stale.yml", nil) resp, err := app.Test(req) if err != nil { @@ -59,6 +60,17 @@ func Test_Static(t *testing.T) { if resp.Header.Get("Content-Length") == "" { t.Fatalf(`%s: Missing Content-Length`, t.Name()) } + req, _ = http.NewRequest("GET", "/yesyes/john/doe", nil) + resp, err = app.Test(req) + if err != nil { + t.Fatalf(`%s: %s`, t.Name(), err) + } + if resp.StatusCode != 200 { + t.Fatalf(`%s: StatusCode %v`, t.Name(), resp.StatusCode) + } + if resp.Header.Get("Content-Length") == "" { + t.Fatalf(`%s: Missing Content-Length`, t.Name()) + } req, _ = http.NewRequest("GET", "/john/stale.yml", nil) resp, err = app.Test(req) if err != nil { @@ -105,6 +117,7 @@ func Test_Group(t *testing.T) { } // func Test_Listen(t *testing.T) { +// t.Parallel() // app := New() // app.Banner = false // go func() { diff --git a/router_test.go b/router_test.go deleted file mode 100644 index b277214c..00000000 --- a/router_test.go +++ /dev/null @@ -1 +0,0 @@ -package fiber diff --git a/utils.go b/utils.go index cf9877e3..2296740f 100644 --- a/utils.go +++ b/utils.go @@ -9,6 +9,7 @@ package fiber import ( "bytes" + "fmt" "net" "os" "path/filepath" @@ -60,6 +61,10 @@ func getRegex(path string) (*regexp.Regexp, error) { func getFiles(root string) (files []string, isDir bool, err error) { root = filepath.Clean(root) + // Check if dir/file exists + if _, err := os.Lstat(root); err != nil { + return files, isDir, fmt.Errorf("%s", err) + } err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if !info.IsDir() { files = append(files, path) diff --git a/utils_test.go b/utils_test.go deleted file mode 100644 index b277214c..00000000 --- a/utils_test.go +++ /dev/null @@ -1 +0,0 @@ -package fiber