diff --git a/internal/handler/mock/middleware.go b/internal/handler/mock/middleware.go index a313c494..5b178c8a 100644 --- a/internal/handler/mock/middleware.go +++ b/internal/handler/mock/middleware.go @@ -7,7 +7,7 @@ import ( "github.com/evg4b/uncors/internal/config" "github.com/evg4b/uncors/internal/contracts" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "github.com/spf13/afero" ) @@ -45,7 +45,7 @@ func (m *Middleware) ServeHTTP(writer http.ResponseWriter, request *http.Request } } - infrastructure.WriteCorsHeaders(header) + infra.WriteCorsHeaders(header) for key, value := range response.Headers { header.Set(key, value) } @@ -58,7 +58,7 @@ func (m *Middleware) ServeHTTP(writer http.ResponseWriter, request *http.Request } if err != nil { - infrastructure.HTTPError(writer, err) + infra.HTTPError(writer, err) return } diff --git a/internal/handler/proxy/middleware.go b/internal/handler/proxy/middleware.go index 8255bd4d..d14e5d17 100644 --- a/internal/handler/proxy/middleware.go +++ b/internal/handler/proxy/middleware.go @@ -5,7 +5,7 @@ import ( "net/http" "strings" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "github.com/evg4b/uncors/internal/contracts" "github.com/evg4b/uncors/internal/helpers" @@ -34,7 +34,7 @@ func NewProxyHandler(options ...HandlerOption) *Handler { func (m *Handler) ServeHTTP(response http.ResponseWriter, request *http.Request) { if err := m.handle(response, request); err != nil { - infrastructure.HTTPError(response, err) + infra.HTTPError(response, err) } } diff --git a/internal/handler/proxy/option.go b/internal/handler/proxy/option.go index ffb3cbef..87c55677 100644 --- a/internal/handler/proxy/option.go +++ b/internal/handler/proxy/option.go @@ -3,11 +3,11 @@ package proxy import ( "net/http" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" ) func (m *Handler) makeOptionsResponse(writer http.ResponseWriter, req *http.Request) error { - infrastructure.WriteCorsHeaders(writer.Header()) + infra.WriteCorsHeaders(writer.Header()) m.logger.PrintResponse(&http.Response{ StatusCode: http.StatusOK, Request: req, diff --git a/internal/handler/proxy/responce.go b/internal/handler/proxy/responce.go index 9360e795..a87a2b3d 100644 --- a/internal/handler/proxy/responce.go +++ b/internal/handler/proxy/responce.go @@ -5,7 +5,7 @@ import ( "io" "net/http" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "github.com/evg4b/uncors/internal/urlreplacer" "github.com/go-http-utils/headers" ) @@ -26,7 +26,7 @@ func (m *Handler) makeUncorsResponse( return err } - infrastructure.WriteCorsHeaders(target.Header()) + infra.WriteCorsHeaders(target.Header()) return copyResponseData(target, original) } diff --git a/internal/handler/static/middleware.go b/internal/handler/static/middleware.go index db310a09..33e25952 100644 --- a/internal/handler/static/middleware.go +++ b/internal/handler/static/middleware.go @@ -9,7 +9,7 @@ import ( "path" "strings" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "github.com/evg4b/uncors/internal/contracts" @@ -50,7 +50,7 @@ func (m *Middleware) ServeHTTP(writer http.ResponseWriter, request *http.Request if errors.Is(err, errNorHandled) { m.next.ServeHTTP(writer, request) } else { - infrastructure.HTTPError(writer, err) + infra.HTTPError(writer, err) } return diff --git a/internal/infrastructure/cors.go b/internal/infra/cors.go similarity index 93% rename from internal/infrastructure/cors.go rename to internal/infra/cors.go index 6db23cab..3d686ed4 100644 --- a/internal/infrastructure/cors.go +++ b/internal/infra/cors.go @@ -1,4 +1,4 @@ -package infrastructure +package infra import ( "net/http" diff --git a/internal/infrastructure/cors_test.go b/internal/infra/cors_test.go similarity index 92% rename from internal/infrastructure/cors_test.go rename to internal/infra/cors_test.go index a3212001..1e627944 100644 --- a/internal/infrastructure/cors_test.go +++ b/internal/infra/cors_test.go @@ -1,10 +1,10 @@ -package infrastructure_test +package infra_test import ( "net/http" "testing" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "github.com/go-http-utils/headers" ) @@ -57,7 +57,7 @@ func TestWriteCorsHeaders(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - infrastructure.WriteCorsHeaders(tt.header) + infra.WriteCorsHeaders(tt.header) }) } } diff --git a/internal/infra/error.go b/internal/infra/error.go new file mode 100644 index 00000000..5372731e --- /dev/null +++ b/internal/infra/error.go @@ -0,0 +1 @@ +package infra diff --git a/internal/infrastructure/http_error.go b/internal/infra/http_error.go similarity index 97% rename from internal/infrastructure/http_error.go rename to internal/infra/http_error.go index d23b7f74..7763f1b5 100644 --- a/internal/infrastructure/http_error.go +++ b/internal/infra/http_error.go @@ -1,4 +1,4 @@ -package infrastructure +package infra import ( "fmt" diff --git a/internal/infrastructure/http_error_test.go b/internal/infra/http_error_test.go similarity index 91% rename from internal/infrastructure/http_error_test.go rename to internal/infra/http_error_test.go index f11931df..959105a8 100644 --- a/internal/infrastructure/http_error_test.go +++ b/internal/infra/http_error_test.go @@ -1,4 +1,4 @@ -package infrastructure_test +package infra_test import ( "net/http" @@ -7,7 +7,7 @@ import ( "github.com/go-http-utils/headers" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "github.com/evg4b/uncors/testing/testutils" "github.com/stretchr/testify/assert" ) @@ -25,7 +25,7 @@ Occurred error: net/http: abort Handler func TestHttpError(t *testing.T) { recorder := httptest.NewRecorder() - infrastructure.HTTPError(recorder, http.ErrAbortHandler) + infra.HTTPError(recorder, http.ErrAbortHandler) t.Run("write correct page", func(t *testing.T) { assert.Equal(t, expectedPage, testutils.ReadBody(t, recorder)) diff --git a/internal/infrastructure/httpclient.go b/internal/infra/httpclient.go similarity index 97% rename from internal/infrastructure/httpclient.go rename to internal/infra/httpclient.go index 765e8ad9..41102ba8 100644 --- a/internal/infrastructure/httpclient.go +++ b/internal/infra/httpclient.go @@ -1,4 +1,4 @@ -package infrastructure +package infra import ( "crypto/tls" diff --git a/internal/infrastructure/httpclient_internal_test.go b/internal/infra/httpclient_internal_test.go similarity index 98% rename from internal/infrastructure/httpclient_internal_test.go rename to internal/infra/httpclient_internal_test.go index ea3f39c6..389cebe0 100644 --- a/internal/infrastructure/httpclient_internal_test.go +++ b/internal/infra/httpclient_internal_test.go @@ -1,5 +1,5 @@ // nolint: lll -package infrastructure +package infra import ( "net/http" diff --git a/internal/infrastructure/noop-logger.go b/internal/infra/noop-logger.go similarity index 83% rename from internal/infrastructure/noop-logger.go rename to internal/infra/noop-logger.go index 83c8f89a..72caa515 100644 --- a/internal/infrastructure/noop-logger.go +++ b/internal/infra/noop-logger.go @@ -1,4 +1,4 @@ -package infrastructure +package infra type NoopLogger struct{} diff --git a/internal/infrastructure/noop-logger_test.go b/internal/infra/noop-logger_test.go similarity index 80% rename from internal/infrastructure/noop-logger_test.go rename to internal/infra/noop-logger_test.go index 21f129a9..dd5c5eb7 100644 --- a/internal/infrastructure/noop-logger_test.go +++ b/internal/infra/noop-logger_test.go @@ -1,17 +1,17 @@ -package infrastructure_test +package infra_test import ( "bytes" "testing" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "github.com/evg4b/uncors/testing/testutils" "github.com/stretchr/testify/assert" ) func TestNoopLogger(t *testing.T) { testMessage := "test message" - noopLogger := infrastructure.NoopLogger{} + noopLogger := infra.NoopLogger{} t.Run("Infof do nothing", testutils.LogTest(func(t *testing.T, output *bytes.Buffer) { noopLogger.Infof(testMessage) diff --git a/internal/infrastructure/panic.go b/internal/infra/panic.go similarity index 85% rename from internal/infrastructure/panic.go rename to internal/infra/panic.go index 66cb38a5..24f50eaa 100644 --- a/internal/infrastructure/panic.go +++ b/internal/infra/panic.go @@ -1,6 +1,6 @@ //go:build release -package infrastructure +package infra func PanicInterceptor(action func(any)) { if recovered := recover(); recovered != nil { diff --git a/internal/infrastructure/panic_debug.go b/internal/infra/panic_debug.go similarity index 77% rename from internal/infrastructure/panic_debug.go rename to internal/infra/panic_debug.go index 22b9a4e0..e2c659a7 100644 --- a/internal/infrastructure/panic_debug.go +++ b/internal/infra/panic_debug.go @@ -1,6 +1,6 @@ //go:build !release -package infrastructure +package infra func PanicInterceptor(_ func(any)) { // stub method diff --git a/internal/infrastructure/panic_test.go b/internal/infra/panic_test.go similarity index 86% rename from internal/infrastructure/panic_test.go rename to internal/infra/panic_test.go index 862039a4..265bba38 100644 --- a/internal/infrastructure/panic_test.go +++ b/internal/infra/panic_test.go @@ -1,10 +1,10 @@ //go:build release -package infrastructure_test +package infra_test import ( "errors" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "testing" "github.com/stretchr/testify/assert" @@ -37,7 +37,7 @@ func TestPanicInterceptor(t *testing.T) { called := false assert.NotPanics(t, func() { - defer infrastructure.PanicInterceptor(func(data any) { + defer infra.PanicInterceptor(func(data any) { called = true assert.Equal(t, testCast.panicData, data) }) diff --git a/internal/infrastructure/error.go b/internal/infrastructure/error.go deleted file mode 100644 index ebb143f4..00000000 --- a/internal/infrastructure/error.go +++ /dev/null @@ -1 +0,0 @@ -package infrastructure diff --git a/main.go b/main.go index 95ae8e65..d5735d5f 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( "golang.org/x/net/context" "github.com/evg4b/uncors/internal/config" - "github.com/evg4b/uncors/internal/infrastructure" + "github.com/evg4b/uncors/internal/infra" "github.com/evg4b/uncors/internal/log" "github.com/evg4b/uncors/internal/ui" "github.com/evg4b/uncors/internal/urlreplacer" @@ -35,7 +35,7 @@ var Version = "X.X.X" const baseAddress = "127.0.0.1" func main() { - defer infrastructure.PanicInterceptor(func(value any) { + defer infra.PanicInterceptor(func(value any) { pterm.Error.Println(value) os.Exit(1) }) @@ -75,12 +75,12 @@ func main() { panic(err) } - httpClient, err := infrastructure.MakeHTTPClient(viper.GetString("proxy")) + httpClient, err := infra.MakeHTTPClient(viper.GetString("proxy")) if err != nil { panic(err) } - finisher := finish.Finisher{Log: infrastructure.NoopLogger{}} + finisher := finish.Finisher{Log: infra.NoopLogger{}} ctx := context.Background()