diff --git a/service_a/internal/domains/common.go b/pkg/errors.go similarity index 79% rename from service_a/internal/domains/common.go rename to pkg/errors.go index 05b8e4f..95a6042 100644 --- a/service_a/internal/domains/common.go +++ b/pkg/errors.go @@ -1,4 +1,4 @@ -package domains +package pkg var ( SQLSTATE_25P02 = "25P02" diff --git a/pkg/go.mod b/pkg/go.mod new file mode 100644 index 0000000..418d4ce --- /dev/null +++ b/pkg/go.mod @@ -0,0 +1,3 @@ +module pkg + +go 1.25.2 diff --git a/service_a/internal/domains/handlers.go b/pkg/handlers.go similarity index 97% rename from service_a/internal/domains/handlers.go rename to pkg/handlers.go index 41f19c2..a12f541 100644 --- a/service_a/internal/domains/handlers.go +++ b/pkg/handlers.go @@ -1,4 +1,4 @@ -package domains +package pkg import ( "encoding/json" diff --git a/service_a/go.mod b/service_a/go.mod index 6189b53..32cea18 100644 --- a/service_a/go.mod +++ b/service_a/go.mod @@ -5,6 +5,7 @@ go 1.25.2 require ( github.com/jackc/pgx/v5 v5.7.6 github.com/stretchr/testify v1.11.1 + pkg v0.0.0-00010101000000-000000000000 ) require ( @@ -20,3 +21,5 @@ require ( golang.org/x/text v0.24.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace pkg => ../pkg diff --git a/service_a/internal/domains/meteo/handlers.go b/service_a/internal/domains/meteo/handlers.go index 1a847c2..4413d3c 100644 --- a/service_a/internal/domains/meteo/handlers.go +++ b/service_a/internal/domains/meteo/handlers.go @@ -8,13 +8,13 @@ import ( "io" "log/slog" "net/http" + "pkg" "servicea/internal/app" - "servicea/internal/domains" "time" ) type Handler struct { - domains.BaseHandler + pkg.BaseHandler s *Service } diff --git a/service_a/internal/domains/meteo/repository.go b/service_a/internal/domains/meteo/repository.go index 861fd09..ed17b09 100644 --- a/service_a/internal/domains/meteo/repository.go +++ b/service_a/internal/domains/meteo/repository.go @@ -3,7 +3,7 @@ package meteo import ( "context" "fmt" - "servicea/internal/domains" + "pkg" "strings" b "github.com/jackc/pgx/v5" @@ -78,7 +78,7 @@ func (pgx *pgxRepo) insertBatch(ctx context.Context, tx b.Tx, fileChecksum strin var batchID int err := tx.QueryRow(ctx, insertBatch, 0, fileChecksum).Scan(&batchID) if err != nil { - if strings.Contains(err.Error(), domains.SQLSTATE_23505) { + if strings.Contains(err.Error(), pkg.SQLSTATE_23505) { return 0, ErrRecordAlreadyExists } return 0, fmt.Errorf("error inserting batch: %w", err) @@ -107,7 +107,7 @@ func (pgx *pgxRepo) insertAcceptedMeteoData(ctx context.Context, tx b.Tx, batchI rowsInserted++ if err != nil { results.Close() - if strings.Contains(err.Error(), domains.SQLSTATE_23505) { + if strings.Contains(err.Error(), pkg.SQLSTATE_23505) { return 0, ErrRecordAlreadyExists } return 0, fmt.Errorf("error executing batch command %d: %w", i, err)