Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ tasks:
- test -f ${GOBIN}/golangci-lint
cmds:
- go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2

test:
desc: Run tests
deps:
- test:install
cmds:
- gotestsum ./... -- -race -count=1 -v

test:install:
desc: Install gotestsum
status:
- test -f ${GOBIN}/gotestsum
cmds:
- go install gotest.tools/gotestsum@latest
30 changes: 7 additions & 23 deletions heimdall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package heimdall
import (
"context"
"log/slog"
"net/http"

"github.com/arthurdotwork/heimdall/internal/config"
internalMiddleware "github.com/arthurdotwork/heimdall/internal/middleware"
Expand All @@ -23,23 +22,13 @@ type Gateway struct {
registry *internalMiddleware.Registry
}

// Config exposes configuration types to public API
type Config = config.Config
type GatewayConfig = config.GatewayConfig
type EndpointConfig = config.EndpointConfig

// Middleware defines the contract for middleware components in Heimdall
type Middleware interface {
Wrap(next http.Handler) http.Handler
}

// MiddlewareFunc is a function type that implements the Middleware interface
type MiddlewareFunc func(http.Handler) http.Handler

// Wrap implements the Middleware interface for MiddlewareFunc
func (f MiddlewareFunc) Wrap(next http.Handler) http.Handler {
return f(next)
}
type (
Config = config.Config
GatewayConfig = config.GatewayConfig
EndpointConfig = config.EndpointConfig
Middleware = internalMiddleware.Middleware
MiddlewareFunc = internalMiddleware.Func
)

// New creates a new gateway instance
func New(configPath string) (*Gateway, error) {
Expand Down Expand Up @@ -133,11 +122,6 @@ func RegisterMiddleware(name string, middleware Middleware) error {
return defaultRegistry.Register(name, middleware)
}

// ResetDefaultRegistry resets the default registry (primarily for testing)
func ResetDefaultRegistry() {
defaultRegistry = internalMiddleware.NewRegistry()
}

// LoadFromFile loads configuration from a file
func LoadFromFile(path string) (*Config, error) {
return config.LoadFromFile(path)
Expand Down
4 changes: 0 additions & 4 deletions heimdall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ func TestNew(t *testing.T) {
})

t.Run("it should load middleware from config", func(t *testing.T) {
// Reset the default registry for this test
heimdall.ResetDefaultRegistry()

// Create test middleware
var globalMiddlewareExecuted, endpointMiddlewareExecuted bool

globalMiddleware := heimdall.MiddlewareFunc(func(next http.Handler) http.Handler {
Expand Down