git » gofer » commit c797d7e

Rename "static" to "file" to avoid confusion

author Alberto Bertogli
2020-06-09 10:52:03 UTC
committer Alberto Bertogli
2020-06-09 10:52:03 UTC
parent 7af09bc75a3a538474e0aaefcf19b9d518e4a048

Rename "static" to "file" to avoid confusion

Since "dir" is also a form of static serving, rename the "static"
route method to "file", to avoid confusion.

config/config.go +1 -1
etc/gofer.schema.cue +1 -1
etc/gofer.yaml +2 -2
server/http.go +3 -3
server/server_test.go +2 -2
test/01-be.yaml +1 -1

diff --git a/config/config.go b/config/config.go
index 2e703a6..a2f7997 100644
--- a/config/config.go
+++ b/config/config.go
@@ -23,7 +23,7 @@ type Config struct {
 type HTTP struct {
 	Proxy    map[string]string
 	Dir      map[string]string
-	Static   map[string]string
+	File     map[string]string
 	Redirect map[string]string
 	CGI      map[string]string
 
diff --git a/etc/gofer.schema.cue b/etc/gofer.schema.cue
index 8bb1fb3..a26a582 100644
--- a/etc/gofer.schema.cue
+++ b/etc/gofer.schema.cue
@@ -25,7 +25,7 @@ https?:
 _http: {
 	dir?: [string]: string
 
-	static?: [string]: string
+	file?: [string]: string
 
 	proxy?: [string]: string
 
diff --git a/etc/gofer.yaml b/etc/gofer.yaml
index 50ae97b..3363965 100644
--- a/etc/gofer.yaml
+++ b/etc/gofer.yaml
@@ -41,8 +41,8 @@ http:
       "/": "/srv/www/"
       #"/other": "/srv/other/"
 
-    # Static individual files.
-    #static:
+    # Individual files.
+    #file:
     #  "/a/file": "/srv/files/file"
 
     # Proxy requests.
diff --git a/server/http.go b/server/http.go
index d640cd0..2dafe3e 100644
--- a/server/http.go
+++ b/server/http.go
@@ -44,7 +44,7 @@ func httpServer(addr string, conf config.HTTP) *http.Server {
 	}{
 		{"proxy", conf.Proxy, makeProxy},
 		{"dir", conf.Dir, makeDir},
-		{"static", conf.Static, makeStatic},
+		{"file", conf.File, makeFile},
 		{"redirect", conf.Redirect, makeRedirect},
 		{"cgi", conf.CGI, makeCGI},
 	}
@@ -247,12 +247,12 @@ func makeDir(from string, to url.URL, conf *config.HTTP) http.Handler {
 	})
 }
 
-func makeStatic(from string, to url.URL, conf *config.HTTP) http.Handler {
+func makeFile(from string, to url.URL, conf *config.HTTP) http.Handler {
 	path := pathOrOpaque(to)
 
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		tr, _ := trace.FromContext(r.Context())
-		tr.Printf("statically serving %q", path)
+		tr.Printf("serving file %q", path)
 		http.ServeFile(w, r, path)
 	})
 }
diff --git a/server/server_test.go b/server/server_test.go
index a9574c1..fd734d3 100644
--- a/server/server_test.go
+++ b/server/server_test.go
@@ -81,7 +81,7 @@ http:
     proxy:
       "/be/": "$BACKEND_URL"
       "localhost/xy/": "$BACKEND_URL"
-    static:
+    file:
       "/static/hola": "$PWD/testdata/hola"
     dir:
       "/dir/": "$PWD/testdata/"
@@ -128,7 +128,7 @@ func TestSimple(t *testing.T) {
 	testGet(t, "http://localhost:"+httpPort+"/be/", 200)
 	testGet(t, "http://localhost:"+httpPort+"/xy/1", 200)
 
-	// Test dir and static schemes.
+	// Test dir and file schemes.
 	testGet(t, "http://"+httpAddr+"/static/hola", 200)
 	testGet(t, "http://"+httpAddr+"/dir/hola", 200)
 	testGet(t, "http://"+httpAddr+"/redir/hola", 200)
diff --git a/test/01-be.yaml b/test/01-be.yaml
index 1f1c5bc..64b813e 100644
--- a/test/01-be.yaml
+++ b/test/01-be.yaml
@@ -11,7 +11,7 @@ http:
     dir:
       "/dir/": "testdata/dir"
       "/authdir/": "testdata/dir"
-    static:
+    file:
       "/file": "testdata/file"
       "/file/second": "testdata/dir/ñaca"
     cgi: