commit 2c1f9ce64560d6b7b1a30777e5f548afc4e2e99e Author: Matthew Dillon Date: Fri Apr 17 13:57:45 2015 -0800 Initial commit diff --git a/jwt.go b/jwt.go new file mode 100644 index 0000000..fe1aef3 --- /dev/null +++ b/jwt.go @@ -0,0 +1,19 @@ +package jwt + +import "errors" + +type Config struct { + Secret string +} + +type JWTMiddleware struct { + config Config +} + +func NewMiddleware(c *Config) (*JWTMiddleware, error) { + if c == nil { + return nil, errors.New("missing configuration") + } + m := &JWTMiddleware{config: *c} + return m, nil +} diff --git a/jwt_test.go b/jwt_test.go new file mode 100644 index 0000000..93b416e --- /dev/null +++ b/jwt_test.go @@ -0,0 +1,23 @@ +package jwt + +import "testing" + +func TestNewJWTMiddleware(t *testing.T) { + config := &Config{ + Secret: "password", + } + middleware, err := NewMiddleware(config) + if err != nil { + t.Fatalf("new middleware: %v", err) + } + if middleware.config.Secret != "password" { + t.Errorf("expected 'password', got %v", middleware.config.Secret) + } +} + +func TestNewJWTMiddlewareNoConfig(t *testing.T) { + _, err := NewMiddleware(nil) + if err == nil { + t.Error("expected configuration error, received none") + } +}