Skip to content

Commit

Permalink
Rename infrastructure module to infra
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed May 21, 2023
1 parent 273475d commit 3c99b3c
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions internal/handler/mock/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/proxy/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/handler/proxy/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/proxy/responce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -26,7 +26,7 @@ func (m *Handler) makeUncorsResponse(
return err
}

infrastructure.WriteCorsHeaders(target.Header())
infra.WriteCorsHeaders(target.Header())

return copyResponseData(target, original)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/static/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/cors.go → internal/infra/cors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infrastructure
package infra

import (
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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)
})
}
}
1 change: 1 addition & 0 deletions internal/infra/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package infra
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infrastructure
package infra

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infrastructure_test
package infra_test

import (
"net/http"
Expand All @@ -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"
)
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infrastructure
package infra

import (
"crypto/tls"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// nolint: lll
package infrastructure
package infra

import (
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infrastructure
package infra

type NoopLogger struct{}

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build release

package infrastructure
package infra

func PanicInterceptor(action func(any)) {
if recovered := recover(); recovered != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !release

package infrastructure
package infra

func PanicInterceptor(_ func(any)) {
// stub method
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
})
Expand Down
1 change: 0 additions & 1 deletion internal/infrastructure/error.go

This file was deleted.

8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
})
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 3c99b3c

Please sign in to comment.