Repository: avenga/couper
Pull request #16 (2020-09-14 08:38:55)

Don't use an underscore in package name
https://blog.golang.org/package-names

> Good package names are short and clear. They are lower case, with no under_scores or mixedCaps.

> Package names may be abbreviated when the abbreviation is familiar to the programmer.

So the package could be renamed to `ac` instead, it is even used as such:

```
import (
  ac "github.com/avenga/couper/access_control"
)
```


Patch:
diff --git a/access_control/ac.go b/accesscontrol/ac.go
similarity index 87%
rename from access_control/ac.go
rename to accesscontrol/ac.go
index b84bfd23..73eae01e 100644
--- a/access_control/ac.go
+++ b/accesscontrol/ac.go
@@ -1,4 +1,4 @@
-package access_control
+package accesscontrol
 
 import "net/http"
 
@@ -6,8 +6,10 @@ var _ AccessControl = ValidateFunc(func(_ *http.Request) error { return nil })
 
 const ContextAccessControlKey = "access_controls"
 
-type Map map[string]AccessControl
-type List []AccessControl
+type (
+	Map  map[string]AccessControl
+	List []AccessControl
+)
 
 type ValidateFunc func(*http.Request) error
 
diff --git a/access_control/jwt.go b/accesscontrol/jwt.go
similarity index 99%
rename from access_control/jwt.go
rename to accesscontrol/jwt.go
index 2f393cda..78d10109 100644
--- a/access_control/jwt.go
+++ b/accesscontrol/jwt.go
@@ -1,4 +1,4 @@
-package access_control
+package accesscontrol
 
 import (
 	"context"
diff --git a/access_control/jwt_algorithm.go b/accesscontrol/jwt_algorithm.go
similarity index 97%
rename from access_control/jwt_algorithm.go
rename to accesscontrol/jwt_algorithm.go
index a6a5f6f1..084fd632 100644
--- a/access_control/jwt_algorithm.go
+++ b/accesscontrol/jwt_algorithm.go
@@ -1,4 +1,4 @@
-package access_control
+package accesscontrol
 
 const (
 	AlgorithmUnknown Algorithm = iota - 1
diff --git a/config/runtime/handler.go b/config/runtime/handler.go
index a21a483e..d453148e 100644
--- a/config/runtime/handler.go
+++ b/config/runtime/handler.go
@@ -15,7 +15,7 @@ import (
 	"github.com/hashicorp/hcl/v2/gohcl"
 	"github.com/sirupsen/logrus"
 
-	ac "github.com/avenga/couper/access_control"
+	ac "github.com/avenga/couper/accesscontrol"
 	"github.com/avenga/couper/config"
 	"github.com/avenga/couper/errors"
 	"github.com/avenga/couper/handler"
diff --git a/eval/context.go b/eval/context.go
index 34958354..7aab1af2 100644
--- a/eval/context.go
+++ b/eval/context.go
@@ -15,7 +15,7 @@ import (
 	"github.com/zclconf/go-cty/cty/function"
 	"github.com/zclconf/go-cty/cty/function/stdlib"
 
-	ac "github.com/avenga/couper/access_control"
+	ac "github.com/avenga/couper/accesscontrol"
 	"github.com/avenga/couper/config/request"
 	"github.com/avenga/couper/eval/lib"
 	"github.com/avenga/couper/internal/seetie"
diff --git a/handler/access_control.go b/handler/access_control.go
index d5067234..1185235b 100644
--- a/handler/access_control.go
+++ b/handler/access_control.go
@@ -3,7 +3,7 @@ package handler
 import (
 	"net/http"
 
-	ac "github.com/avenga/couper/access_control"
+	ac "github.com/avenga/couper/accesscontrol"
 	"github.com/avenga/couper/errors"
 )
 
diff --git a/server/muxer.go b/server/muxer.go
index bc0464c8..693b2ec1 100644
--- a/server/muxer.go
+++ b/server/muxer.go
@@ -4,7 +4,7 @@ import (
 	"net/http"
 	"strings"
 
-	ac "github.com/avenga/couper/access_control"
+	ac "github.com/avenga/couper/accesscontrol"
 	"github.com/avenga/couper/config/runtime"
 	"github.com/avenga/couper/errors"
 	"github.com/avenga/couper/handler"


Test patch:
diff --git a/access_control/jwt_test.go b/accesscontrol/jwt_test.go
similarity index 98%
rename from access_control/jwt_test.go
rename to accesscontrol/jwt_test.go
index c754506d..ad7a785d 100644
--- a/access_control/jwt_test.go
+++ b/accesscontrol/jwt_test.go
@@ -1,4 +1,4 @@
-package access_control_test
+package accesscontrol_test
 
 import (
 	"crypto/rand"
@@ -13,7 +13,7 @@ import (
 
 	"github.com/dgrijalva/jwt-go/v4"
 
-	ac "github.com/avenga/couper/access_control"
+	ac "github.com/avenga/couper/accesscontrol"
 )
 
 func TestJWT_Validate(t *testing.T) {
diff --git a/handler/access_control_test.go b/handler/access_control_test.go
index 8112bf36..60394e47 100644
--- a/handler/access_control_test.go
+++ b/handler/access_control_test.go
@@ -6,13 +6,13 @@ import (
 	"net/http/httptest"
 	"testing"
 
-	"github.com/avenga/couper/access_control"
+	"github.com/avenga/couper/accesscontrol"
 	"github.com/avenga/couper/errors"
 )
 
 func TestAccessControl_ServeHTTP(t *testing.T) {
 	type fields struct {
-		ac        access_control.List
+		ac        accesscontrol.List
 		protected http.Handler
 	}
 
@@ -25,17 +25,17 @@ func TestAccessControl_ServeHTTP(t *testing.T) {
 		{"no access control", fields{nil, http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
 			rw.WriteHeader(http.StatusNoContent)
 		})}, httptest.NewRequest("GET", "http://ac.test/", nil), http.StatusNoContent},
-		{"with access control valid req", fields{access_control.List{access_control.ValidateFunc(func(r *http.Request) error {
+		{"with access control valid req", fields{accesscontrol.List{accesscontrol.ValidateFunc(func(r *http.Request) error {
 			return nil // valid
 		})}, http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
 			rw.WriteHeader(http.StatusNoContent)
 		})}, httptest.NewRequest("GET", "http://ac.test/", nil), http.StatusNoContent},
-		{"with access control invalid req/empty token", fields{access_control.List{access_control.ValidateFunc(func(r *http.Request) error {
-			return access_control.ErrorEmptyToken
+		{"with access control invalid req/empty token", fields{accesscontrol.List{accesscontrol.ValidateFunc(func(r *http.Request) error {
+			return accesscontrol.ErrorEmptyToken
 		})}, http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
 			rw.WriteHeader(http.StatusGone)
 		})}, httptest.NewRequest("GET", "http://ac.test/", nil), http.StatusUnauthorized},
-		{"with access control invalid req", fields{access_control.List{access_control.ValidateFunc(func(r *http.Request) error {
+		{"with access control invalid req", fields{accesscontrol.List{accesscontrol.ValidateFunc(func(r *http.Request) error {
 			return fmt.Errorf("no! ")
 		})}, http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
 			rw.WriteHeader(http.StatusGone)