diff --git a/cmd/root.go b/cmd/root.go index fce26b27..4f3facb8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,7 +7,7 @@ import ( "strings" _ "github.com/bombsimon/logrusr/v3" - "github.com/formancehq/go-libs/sharedotlp/pkg/sharedotlptraces" + "github.com/formancehq/go-libs/otlp/otlptraces" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -68,7 +68,7 @@ func rootCommand() *cobra.Command { server.Flags().Bool(authBearerUseScopesFlag, false, "Use scopes as defined by rfc https://datatracker.ietf.org/doc/html/rfc8693") - sharedotlptraces.InitOTLPTracesFlags(server.Flags()) + otlptraces.InitOTLPTracesFlags(server.Flags()) viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) viper.AutomaticEnv() diff --git a/cmd/server.go b/cmd/server.go index 686cdbc6..08a0a600 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -3,7 +3,7 @@ package cmd import ( "strings" - "github.com/formancehq/go-libs/sharedotlp/pkg/sharedotlptraces" + "github.com/formancehq/go-libs/otlp/otlptraces" "github.com/bombsimon/logrusr/v3" "github.com/formancehq/payments/internal/app/api" @@ -13,11 +13,11 @@ import ( "github.com/Shopify/sarama" "github.com/ThreeDotsLabs/watermill/message" - "github.com/formancehq/go-libs/sharedlogging" - "github.com/formancehq/go-libs/sharedlogging/sharedlogginglogrus" - "github.com/formancehq/go-libs/sharedpublish" - "github.com/formancehq/go-libs/sharedpublish/sharedpublishhttp" - "github.com/formancehq/go-libs/sharedpublish/sharedpublishkafka" + "github.com/formancehq/go-libs/logging" + "github.com/formancehq/go-libs/logging/logginglogrus" + "github.com/formancehq/go-libs/publish" + "github.com/formancehq/go-libs/publish/publishhttp" + "github.com/formancehq/go-libs/publish/publishkafka" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -76,41 +76,41 @@ func runServer(cmd *cobra.Command, args []string) error { } options = append(options, databaseOptions) - options = append(options, sharedotlptraces.CLITracesModule(viper.GetViper())) + options = append(options, otlptraces.CLITracesModule(viper.GetViper())) options = append(options, - fx.Provide(fx.Annotate(func(p message.Publisher) *sharedpublish.TopicMapperPublisher { - return sharedpublish.NewTopicMapperPublisher(p, topicsMapping()) - }, fx.As(new(sharedpublish.Publisher))))) + fx.Provide(fx.Annotate(func(p message.Publisher) *publish.TopicMapperPublisher { + return publish.NewTopicMapperPublisher(p, topicsMapping()) + }, fx.As(new(publish.Publisher))))) options = append(options, api.HTTPModule()) - options = append(options, sharedpublish.Module()) + options = append(options, publish.Module()) switch { case viper.GetBool(publisherHTTPEnabledFlag): - options = append(options, sharedpublishhttp.Module()) + options = append(options, publishhttp.Module()) case viper.GetBool(publisherKafkaEnabledFlag): options = append(options, - sharedpublishkafka.Module(serviceName, viper.GetStringSlice(publisherKafkaBrokerFlag)...), - sharedpublishkafka.ProvideSaramaOption( - sharedpublishkafka.WithConsumerReturnErrors(), - sharedpublishkafka.WithProducerReturnSuccess(), + publishkafka.Module(serviceName, viper.GetStringSlice(publisherKafkaBrokerFlag)...), + publishkafka.ProvideSaramaOption( + publishkafka.WithConsumerReturnErrors(), + publishkafka.WithProducerReturnSuccess(), ), ) if viper.GetBool(publisherKafkaTLSEnabled) { - options = append(options, sharedpublishkafka.ProvideSaramaOption(sharedpublishkafka.WithTLS())) + options = append(options, publishkafka.ProvideSaramaOption(publishkafka.WithTLS())) } if viper.GetBool(publisherKafkaSASLEnabled) { - options = append(options, sharedpublishkafka.ProvideSaramaOption( - sharedpublishkafka.WithSASLEnabled(), - sharedpublishkafka.WithSASLCredentials( + options = append(options, publishkafka.ProvideSaramaOption( + publishkafka.WithSASLEnabled(), + publishkafka.WithSASLCredentials( viper.GetString(publisherKafkaSASLUsername), viper.GetString(publisherKafkaSASLPassword), ), - sharedpublishkafka.WithSASLMechanism(sarama.SASLMechanism(viper.GetString(publisherKafkaSASLMechanism))), - sharedpublishkafka.WithSASLScramClient(setSCRAMClient), + publishkafka.WithSASLMechanism(sarama.SASLMechanism(viper.GetString(publisherKafkaSASLMechanism))), + publishkafka.WithSASLScramClient(setSCRAMClient), )) } } @@ -142,7 +142,7 @@ func setLogger() { log.SetFormatter(&logrus.JSONFormatter{}) } - sharedlogging.SetFactory(sharedlogging.StaticLoggerFactory(sharedlogginglogrus.New(log))) + logging.SetFactory(logging.StaticLoggerFactory(logginglogrus.New(log))) // Add a dedicated logger for opentelemetry in case of error otel.SetLogger(logrusr.New(logrus.New().WithField("component", "otlp"))) @@ -178,14 +178,14 @@ func setSCRAMClient() sarama.SCRAMClient { switch viper.GetInt(publisherKafkaSASLScramSHASize) { case 512: - fn = sharedpublishkafka.SHA512 + fn = publishkafka.SHA512 case 256: - fn = sharedpublishkafka.SHA256 + fn = publishkafka.SHA256 default: panic("sha size not handled") } - return &sharedpublishkafka.XDGSCRAMClient{ + return &publishkafka.XDGSCRAMClient{ HashGeneratorFcn: fn, } } diff --git a/go.mod b/go.mod index 8dd4f4f6..e7db6fc8 100644 --- a/go.mod +++ b/go.mod @@ -7,9 +7,7 @@ require ( github.com/ThreeDotsLabs/watermill v1.1.1 github.com/bombsimon/logrusr/v3 v3.1.0 github.com/davecgh/go-spew v1.1.1 - github.com/formancehq/go-libs v1.3.0 - github.com/formancehq/go-libs/sharedapi v0.0.0-20221228150855-8e3cef21df97 - github.com/formancehq/go-libs/sharedotlp v0.0.0-20221228150855-8e3cef21df97 + github.com/formancehq/go-libs v1.4.1 github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/jackc/pgx/v5 v5.2.0 @@ -60,7 +58,7 @@ require ( github.com/golang/glog v1.0.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect @@ -115,7 +113,7 @@ require ( golang.org/x/net v0.4.0 // indirect golang.org/x/sys v0.3.0 // indirect golang.org/x/text v0.5.0 // indirect - google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect + google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect google.golang.org/grpc v1.51.0 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index e30a4ed0..cf405e9b 100644 --- a/go.sum +++ b/go.sum @@ -107,19 +107,13 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/formancehq/go-libs v1.3.0 h1:Ogs/B9FcoGHl2yF0TeTrBoGejKQk0G7XH6pFwgCod3U= -github.com/formancehq/go-libs v1.3.0/go.mod h1:9pIcaXQR4O1biXDfhFurYJZw1piU6sJk+0Vqvu+92ng= -github.com/formancehq/go-libs/sharedapi v0.0.0-20221228150855-8e3cef21df97 h1:9pP+VnP7C7dJpWuPlayPainZ01kqcIVu13nSf1wMVto= -github.com/formancehq/go-libs/sharedapi v0.0.0-20221228150855-8e3cef21df97/go.mod h1:PMf25p7rXNJkc/LIwvf0AmGfAo1NqwQG+5emONMrurA= -github.com/formancehq/go-libs/sharedotlp v0.0.0-20221228150855-8e3cef21df97 h1:png26T7Aot5+xNIoI29jo5VNA19rr/t0cGYR6NYW5qI= -github.com/formancehq/go-libs/sharedotlp v0.0.0-20221228150855-8e3cef21df97/go.mod h1:sY3SY+G3EDNd9sELK6UbDYx3Ah+hJJsEnBU9Dq28ZSw= +github.com/formancehq/go-libs v1.4.1 h1:rUKfUyZFq9aid+JUIqKN8Mk80Lx06Bx7AreHj+9vyTo= +github.com/formancehq/go-libs v1.4.1/go.mod h1:IK1zDIGRPi/o8sSApIc1W0VC1Y0DGdADzxvpbqlD8fk= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gibson042/canonicaljson-go v1.0.3 h1:EAyF8L74AWabkyUmrvEFHEt/AGFQeD6RfwbAuf0j1bI= -github.com/gibson042/canonicaljson-go v1.0.3/go.mod h1:DsLpJTThXyGNO+KZlI85C1/KDcImpP67k/RKVjcaEqo= github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= @@ -215,8 +209,8 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+ github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 h1:t7uX3JBHdVwAi3G7sSSdbsk8NfgA+LnUS88V/2EKaA0= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0/go.mod h1:4OGVnY4qf2+gw+ssiHbW+pq4mo2yko94YxxMmXZ7jCA= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 h1:1JYBfzqrWPcCclBwxFCPAou9n+q86mfnu7NAeHfte7A= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0/go.mod h1:YDZoGHuwE+ov0c8smSH49WLF3F2LaWnYYuDVd+EWrc0= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -298,7 +292,6 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= -github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc= github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -733,8 +726,8 @@ google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 h1:jmIfw8+gSvXcZSgaFAGyInDXeWzUhvYH57G/5GKMn70= -google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef h1:uQ2vjV/sHTsWSqdKeLqmwitzgvjMl7o4IdtHwUDXSJY= +google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/internal/app/api/accounts.go b/internal/app/api/accounts.go index 8b0f24ea..cc061ae9 100644 --- a/internal/app/api/accounts.go +++ b/internal/app/api/accounts.go @@ -10,7 +10,7 @@ import ( "github.com/formancehq/payments/internal/app/models" "github.com/formancehq/payments/internal/app/storage" - "github.com/formancehq/go-libs/sharedapi" + "github.com/formancehq/go-libs/api" "github.com/pkg/errors" ) @@ -95,7 +95,7 @@ func listAccountsHandler(repo listAccountsRepository) http.HandlerFunc { } } - err = json.NewEncoder(w).Encode(sharedapi.BaseResponse[[]*accountResponse]{ + err = json.NewEncoder(w).Encode(api.BaseResponse[[]*accountResponse]{ Data: &data, }) if err != nil { diff --git a/internal/app/api/connector.go b/internal/app/api/connector.go index 775a0252..f55dde9d 100644 --- a/internal/app/api/connector.go +++ b/internal/app/api/connector.go @@ -15,17 +15,17 @@ import ( "github.com/gorilla/mux" - "github.com/formancehq/go-libs/sharedapi" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/api" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/integration" ) func handleErrorBadRequest(w http.ResponseWriter, r *http.Request, err error) { w.WriteHeader(http.StatusBadRequest) - sharedlogging.GetLogger(r.Context()).Error(err) + logging.GetLogger(r.Context()).Error(err) // TODO: Opentracing - err = json.NewEncoder(w).Encode(sharedapi.ErrorResponse{ + err = json.NewEncoder(w).Encode(api.ErrorResponse{ ErrorCode: http.StatusText(http.StatusBadRequest), ErrorMessage: err.Error(), }) @@ -37,9 +37,9 @@ func handleErrorBadRequest(w http.ResponseWriter, r *http.Request, err error) { func handleError(w http.ResponseWriter, r *http.Request, err error) { w.WriteHeader(http.StatusInternalServerError) - sharedlogging.GetLogger(r.Context()).Error(err) + logging.GetLogger(r.Context()).Error(err) // TODO: Opentracing - err = json.NewEncoder(w).Encode(sharedapi.ErrorResponse{ + err = json.NewEncoder(w).Encode(api.ErrorResponse{ ErrorCode: "INTERNAL", ErrorMessage: err.Error(), }) diff --git a/internal/app/api/connectormodule.go b/internal/app/api/connectormodule.go index 3f5a5766..be8f0d40 100644 --- a/internal/app/api/connectormodule.go +++ b/internal/app/api/connectormodule.go @@ -12,8 +12,8 @@ import ( "github.com/formancehq/payments/internal/app/storage" - "github.com/formancehq/go-libs/sharedlogging" - "github.com/formancehq/go-libs/sharedpublish" + "github.com/formancehq/go-libs/logging" + "github.com/formancehq/go-libs/publish" "github.com/formancehq/payments/internal/app/ingestion" "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/task" @@ -30,9 +30,9 @@ func addConnector[ConnectorConfig models.ConnectorConfigObject](loader integrati ) fx.Option { return fx.Options( fx.Provide(func(store *storage.Storage, - publisher sharedpublish.Publisher, + publisher publish.Publisher, ) *integration.ConnectorManager[ConnectorConfig] { - logger := sharedlogging.GetLogger(context.Background()) + logger := logging.GetLogger(context.Background()) schedulerFactory := integration.TaskSchedulerFactoryFn(func( resolver task.Resolver, maxTasks int, diff --git a/internal/app/api/module.go b/internal/app/api/module.go index e197676d..48f04bd2 100644 --- a/internal/app/api/module.go +++ b/internal/app/api/module.go @@ -8,15 +8,15 @@ import ( "strings" "time" - "github.com/formancehq/go-libs/sharedapi" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/api" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/connectors/bankingcircle" "github.com/formancehq/payments/internal/app/connectors/currencycloud" + "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/oauth2/oauth2introspect" - "github.com/formancehq/go-libs/sharedauth" - sharedotlp "github.com/formancehq/go-libs/sharedotlp/pkg" + "github.com/formancehq/go-libs/otlp" "github.com/formancehq/payments/internal/app/connectors/dummypay" "github.com/formancehq/payments/internal/app/connectors/modulr" "github.com/formancehq/payments/internal/app/connectors/stripe" @@ -77,7 +77,7 @@ func HTTPModule() fx.Option { func httpRecoveryFunc(ctx context.Context, e interface{}) { if viper.GetBool(otelTracesFlag) { - sharedotlp.RecordAsError(ctx, e) + otlp.RecordAsError(ctx, e) } else { logrus.Errorln(e) debug.PrintStack() @@ -99,28 +99,28 @@ func httpServeFunc(handler http.Handler) http.Handler { }) } -func sharedAuthMethods() []sharedauth.Method { - methods := make([]sharedauth.Method, 0) +func sharedAuthMethods() []auth.Method { + methods := make([]auth.Method, 0) if viper.GetBool(authBasicEnabledFlag) { - credentials := sharedauth.Credentials{} + credentials := auth.Credentials{} for _, kv := range viper.GetStringSlice(authBasicCredentialsFlag) { parts := strings.SplitN(kv, ":", 2) - credentials[parts[0]] = sharedauth.Credential{ + credentials[parts[0]] = auth.Credential{ Password: parts[1], } } - methods = append(methods, sharedauth.NewHTTPBasicMethod(credentials)) + methods = append(methods, auth.NewHTTPBasicMethod(credentials)) } if viper.GetBool(authBearerEnabledFlag) { - methods = append(methods, sharedauth.NewHttpBearerMethod( - sharedauth.NewIntrospectionValidator( + methods = append(methods, auth.NewHttpBearerMethod( + auth.NewIntrospectionValidator( oauth2introspect.NewIntrospecter(viper.GetString(authBearerIntrospectURLFlag)), viper.GetBool(authBearerAudiencesWildcardFlag), - sharedauth.AudienceIn(viper.GetStringSlice(authBearerAudienceFlag)...), + auth.AudienceIn(viper.GetStringSlice(authBearerAudienceFlag)...), ), )) } @@ -130,9 +130,9 @@ func sharedAuthMethods() []sharedauth.Method { func handleServerError(w http.ResponseWriter, r *http.Request, err error) { w.WriteHeader(http.StatusInternalServerError) - sharedlogging.GetLogger(r.Context()).Error(err) + logging.GetLogger(r.Context()).Error(err) // TODO: Opentracing - err = json.NewEncoder(w).Encode(sharedapi.ErrorResponse{ + err = json.NewEncoder(w).Encode(api.ErrorResponse{ ErrorCode: "INTERNAL", ErrorMessage: err.Error(), }) @@ -143,9 +143,9 @@ func handleServerError(w http.ResponseWriter, r *http.Request, err error) { func handleValidationError(w http.ResponseWriter, r *http.Request, err error) { w.WriteHeader(http.StatusBadRequest) - sharedlogging.GetLogger(r.Context()).Error(err) + logging.GetLogger(r.Context()).Error(err) // TODO: Opentracing - err = json.NewEncoder(w).Encode(sharedapi.ErrorResponse{ + err = json.NewEncoder(w).Encode(api.ErrorResponse{ ErrorCode: "VALIDATION", ErrorMessage: err.Error(), }) diff --git a/internal/app/api/payments.go b/internal/app/api/payments.go index 8ea28cf9..fb285c37 100644 --- a/internal/app/api/payments.go +++ b/internal/app/api/payments.go @@ -13,7 +13,7 @@ import ( "github.com/formancehq/payments/internal/app/models" "github.com/formancehq/payments/internal/app/storage" - "github.com/formancehq/go-libs/sharedapi" + "github.com/formancehq/go-libs/api" "github.com/gorilla/mux" "github.com/pkg/errors" ) @@ -165,7 +165,7 @@ func listPaymentsHandler(repo listPaymentsRepository) http.HandlerFunc { } } - err = json.NewEncoder(w).Encode(sharedapi.BaseResponse[[]*paymentResponse]{ + err = json.NewEncoder(w).Encode(api.BaseResponse[[]*paymentResponse]{ Data: &data, }) if err != nil { @@ -238,7 +238,7 @@ func readPaymentHandler(repo readPaymentRepository) http.HandlerFunc { } } - err = json.NewEncoder(w).Encode(sharedapi.BaseResponse[paymentResponse]{ + err = json.NewEncoder(w).Encode(api.BaseResponse[paymentResponse]{ Data: &data, }) if err != nil { diff --git a/internal/app/api/readconnectors.go b/internal/app/api/readconnectors.go index a9bf2b4d..8457d1e6 100644 --- a/internal/app/api/readconnectors.go +++ b/internal/app/api/readconnectors.go @@ -7,7 +7,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedapi" + "github.com/formancehq/go-libs/api" ) type readConnectorsRepository interface { @@ -42,7 +42,7 @@ func readConnectorsHandler(repo readConnectorsRepository) http.HandlerFunc { } err = json.NewEncoder(w).Encode( - sharedapi.BaseResponse[[]readConnectorsResponseElement]{ + api.BaseResponse[[]readConnectorsResponseElement]{ Data: &data, }) if err != nil { diff --git a/internal/app/api/router.go b/internal/app/api/router.go index 7fb219c1..b1bf2022 100644 --- a/internal/app/api/router.go +++ b/internal/app/api/router.go @@ -7,7 +7,7 @@ import ( "github.com/formancehq/payments/internal/app/storage" - "github.com/formancehq/go-libs/sharedauth" + "github.com/formancehq/go-libs/auth" "github.com/formancehq/payments/internal/app/integration" "github.com/gorilla/mux" "github.com/spf13/viper" @@ -31,7 +31,7 @@ func httpRouter(store *storage.Storage, connectorHandlers []connectorHandler) (* authGroup := rootMux.Name("authenticated").Subrouter() if methods := sharedAuthMethods(); len(methods) > 0 { - authGroup.Use(sharedauth.Middleware(methods...)) + authGroup.Use(auth.Middleware(methods...)) } authGroup.Path("/payments").Methods(http.MethodGet).Handler(listPaymentsHandler(store)) diff --git a/internal/app/connectors/bankingcircle/client.go b/internal/app/connectors/bankingcircle/client.go index a91fb3e0..8666b637 100644 --- a/internal/app/connectors/bankingcircle/client.go +++ b/internal/app/connectors/bankingcircle/client.go @@ -8,7 +8,7 @@ import ( "net/http" "time" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" ) @@ -21,7 +21,7 @@ type client struct { endpoint string authorizationEndpoint string - logger sharedlogging.Logger + logger logging.Logger accessToken string accessTokenExpiresAt time.Time @@ -34,7 +34,7 @@ func newHTTPClient() *http.Client { } } -func newClient(username, password, endpoint, authorizationEndpoint string, logger sharedlogging.Logger) (*client, error) { +func newClient(username, password, endpoint, authorizationEndpoint string, logger logging.Logger) (*client, error) { c := &client{ httpClient: newHTTPClient(), diff --git a/internal/app/connectors/bankingcircle/loader.go b/internal/app/connectors/bankingcircle/loader.go index 34b94a14..9dac0639 100644 --- a/internal/app/connectors/bankingcircle/loader.go +++ b/internal/app/connectors/bankingcircle/loader.go @@ -1,7 +1,7 @@ package bankingcircle import ( - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/models" "github.com/formancehq/payments/internal/app/task" @@ -12,7 +12,7 @@ const Name = models.ConnectorProviderBankingCircle // NewLoader creates a new loader. func NewLoader() integration.Loader[Config] { loader := integration.NewLoaderBuilder[Config](Name). - WithLoad(func(logger sharedlogging.Logger, config Config) integration.Connector { + WithLoad(func(logger logging.Logger, config Config) integration.Connector { return integration.NewConnectorBuilder(). WithInstall(func(ctx task.ConnectorContext) error { taskDescriptor, err := models.EncodeTaskDescriptor(TaskDescriptor{ diff --git a/internal/app/connectors/bankingcircle/task_fetch_payments.go b/internal/app/connectors/bankingcircle/task_fetch_payments.go index 753188a0..a3f9181f 100644 --- a/internal/app/connectors/bankingcircle/task_fetch_payments.go +++ b/internal/app/connectors/bankingcircle/task_fetch_payments.go @@ -9,10 +9,10 @@ import ( "github.com/formancehq/payments/internal/app/ingestion" "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) -func taskFetchPayments(logger sharedlogging.Logger, client *client) task.Task { +func taskFetchPayments(logger logging.Logger, client *client) task.Task { return func( ctx context.Context, scheduler task.Scheduler, diff --git a/internal/app/connectors/bankingcircle/task_resolve.go b/internal/app/connectors/bankingcircle/task_resolve.go index 7560e6f6..19d49e1b 100644 --- a/internal/app/connectors/bankingcircle/task_resolve.go +++ b/internal/app/connectors/bankingcircle/task_resolve.go @@ -7,7 +7,7 @@ import ( "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) const ( @@ -20,7 +20,7 @@ type TaskDescriptor struct { Key string `json:"key" yaml:"key" bson:"key"` } -func resolveTasks(logger sharedlogging.Logger, config Config) func(taskDefinition models.TaskDescriptor) task.Task { +func resolveTasks(logger logging.Logger, config Config) func(taskDefinition models.TaskDescriptor) task.Task { bankingCircleClient, err := newClient(config.Username, config.Password, config.Endpoint, config.AuthorizationEndpoint, logger) if err != nil { logger.Error(err) diff --git a/internal/app/connectors/currencycloud/connector.go b/internal/app/connectors/currencycloud/connector.go index 8427f218..69105ba5 100644 --- a/internal/app/connectors/currencycloud/connector.go +++ b/internal/app/connectors/currencycloud/connector.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/task" ) @@ -13,7 +13,7 @@ import ( const Name = models.ConnectorProviderCurrencyCloud type Connector struct { - logger sharedlogging.Logger + logger logging.Logger cfg Config } @@ -36,7 +36,7 @@ func (c *Connector) Resolve(descriptor models.TaskDescriptor) task.Task { var _ integration.Connector = &Connector{} -func newConnector(logger sharedlogging.Logger, cfg Config) *Connector { +func newConnector(logger logging.Logger, cfg Config) *Connector { return &Connector{ logger: logger.WithFields(map[string]any{ "component": "connector", diff --git a/internal/app/connectors/currencycloud/loader.go b/internal/app/connectors/currencycloud/loader.go index 2f0cac56..aaf6d793 100644 --- a/internal/app/connectors/currencycloud/loader.go +++ b/internal/app/connectors/currencycloud/loader.go @@ -1,7 +1,7 @@ package currencycloud import ( - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/models" ) @@ -18,7 +18,7 @@ func (l *Loader) Name() models.ConnectorProvider { return Name } -func (l *Loader) Load(logger sharedlogging.Logger, config Config) integration.Connector { +func (l *Loader) Load(logger logging.Logger, config Config) integration.Connector { return newConnector(logger, config) } diff --git a/internal/app/connectors/currencycloud/task_fetch_transactions.go b/internal/app/connectors/currencycloud/task_fetch_transactions.go index 7e6f722f..a188d5a0 100644 --- a/internal/app/connectors/currencycloud/task_fetch_transactions.go +++ b/internal/app/connectors/currencycloud/task_fetch_transactions.go @@ -14,10 +14,10 @@ import ( "github.com/formancehq/payments/internal/app/ingestion" "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) -func taskFetchTransactions(logger sharedlogging.Logger, client *client.Client, config Config) task.Task { +func taskFetchTransactions(logger logging.Logger, client *client.Client, config Config) task.Task { return func( ctx context.Context, ingester ingestion.Ingester, @@ -35,7 +35,7 @@ func taskFetchTransactions(logger sharedlogging.Logger, client *client.Client, c } } -func ingestTransactions(ctx context.Context, logger sharedlogging.Logger, +func ingestTransactions(ctx context.Context, logger logging.Logger, client *client.Client, ingester ingestion.Ingester, ) error { page := 1 diff --git a/internal/app/connectors/currencycloud/task_resolve.go b/internal/app/connectors/currencycloud/task_resolve.go index 238a6d2e..c1bd1e36 100644 --- a/internal/app/connectors/currencycloud/task_resolve.go +++ b/internal/app/connectors/currencycloud/task_resolve.go @@ -8,7 +8,7 @@ import ( "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) const ( @@ -20,7 +20,7 @@ type TaskDescriptor struct { Name string `json:"name" yaml:"name" bson:"name"` } -func resolveTasks(logger sharedlogging.Logger, config Config) task.Task { +func resolveTasks(logger logging.Logger, config Config) task.Task { return func(ctx context.Context, taskDescriptor TaskDescriptor) task.Task { currencyCloudClient, err := client.NewClient(ctx, config.LoginID, config.APIKey, config.Endpoint) if err != nil { diff --git a/internal/app/connectors/dummypay/connector.go b/internal/app/connectors/dummypay/connector.go index 1efb4430..ca394866 100644 --- a/internal/app/connectors/dummypay/connector.go +++ b/internal/app/connectors/dummypay/connector.go @@ -8,7 +8,7 @@ import ( "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) // Name is the name of the connector. @@ -16,7 +16,7 @@ const Name = models.ConnectorProviderDummyPay // Connector is the connector for the dummy payment connector. type Connector struct { - logger sharedlogging.Logger + logger logging.Logger cfg Config fs fs } @@ -70,7 +70,7 @@ func (c *Connector) Resolve(descriptor models.TaskDescriptor) task.Task { return handleResolve(c.cfg, taskDescriptor, c.fs) } -func newConnector(logger sharedlogging.Logger, cfg Config, fs fs) *Connector { +func newConnector(logger logging.Logger, cfg Config, fs fs) *Connector { return &Connector{ logger: logger.WithFields(map[string]any{ "component": "connector", diff --git a/internal/app/connectors/dummypay/connector_test.go b/internal/app/connectors/dummypay/connector_test.go index c41c102d..39576448 100644 --- a/internal/app/connectors/dummypay/connector_test.go +++ b/internal/app/connectors/dummypay/connector_test.go @@ -9,7 +9,7 @@ import ( "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/stretchr/testify/assert" ) @@ -37,7 +37,7 @@ func TestConnector(t *testing.T) { t.Parallel() config := Config{} - logger := sharedlogging.GetLogger(context.Background()) + logger := logging.GetLogger(context.Background()) fileSystem := newTestFS() diff --git a/internal/app/connectors/dummypay/loader.go b/internal/app/connectors/dummypay/loader.go index 350803f3..319caa3b 100644 --- a/internal/app/connectors/dummypay/loader.go +++ b/internal/app/connectors/dummypay/loader.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/connectors" "github.com/formancehq/payments/internal/app/integration" ) @@ -44,7 +44,7 @@ func (l *Loader) ApplyDefaults(cfg Config) Config { } // Load returns the connector. -func (l *Loader) Load(logger sharedlogging.Logger, config Config) integration.Connector { +func (l *Loader) Load(logger logging.Logger, config Config) integration.Connector { return newConnector(logger, config, newFS()) } diff --git a/internal/app/connectors/dummypay/loader_test.go b/internal/app/connectors/dummypay/loader_test.go index d960cc92..3e0776e1 100644 --- a/internal/app/connectors/dummypay/loader_test.go +++ b/internal/app/connectors/dummypay/loader_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/connectors" "github.com/stretchr/testify/assert" ) @@ -15,7 +15,7 @@ func TestLoader(t *testing.T) { t.Parallel() config := Config{} - logger := sharedlogging.GetLogger(context.Background()) + logger := logging.GetLogger(context.Background()) loader := NewLoader() diff --git a/internal/app/connectors/dummypay/task_read_files.go b/internal/app/connectors/dummypay/task_read_files.go index 7592c74e..a88c0aa9 100644 --- a/internal/app/connectors/dummypay/task_read_files.go +++ b/internal/app/connectors/dummypay/task_read_files.go @@ -8,7 +8,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/task" "github.com/spf13/afero" ) @@ -26,7 +26,7 @@ func newTaskReadFiles() TaskDescriptor { // taskReadFiles creates a task that reads files from a given directory. // Only reads files with the generatedFilePrefix in their name. func taskReadFiles(config Config, fs fs) task.Task { - return func(ctx context.Context, logger sharedlogging.Logger, + return func(ctx context.Context, logger logging.Logger, scheduler task.Scheduler, ) error { for { diff --git a/internal/app/connectors/modulr/connector.go b/internal/app/connectors/modulr/connector.go index 2fc61a59..f660d132 100644 --- a/internal/app/connectors/modulr/connector.go +++ b/internal/app/connectors/modulr/connector.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/task" ) @@ -13,7 +13,7 @@ import ( const Name = models.ConnectorProviderModulr type Connector struct { - logger sharedlogging.Logger + logger logging.Logger cfg Config } @@ -44,7 +44,7 @@ func (c *Connector) Resolve(descriptor models.TaskDescriptor) task.Task { var _ integration.Connector = &Connector{} -func newConnector(logger sharedlogging.Logger, cfg Config) *Connector { +func newConnector(logger logging.Logger, cfg Config) *Connector { return &Connector{ logger: logger.WithFields(map[string]any{ "component": "connector", diff --git a/internal/app/connectors/modulr/loader.go b/internal/app/connectors/modulr/loader.go index 9cd62035..8c7bf028 100644 --- a/internal/app/connectors/modulr/loader.go +++ b/internal/app/connectors/modulr/loader.go @@ -1,7 +1,7 @@ package modulr import ( - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/models" ) @@ -18,7 +18,7 @@ func (l *Loader) Name() models.ConnectorProvider { return Name } -func (l *Loader) Load(logger sharedlogging.Logger, config Config) integration.Connector { +func (l *Loader) Load(logger logging.Logger, config Config) integration.Connector { return newConnector(logger, config) } diff --git a/internal/app/connectors/modulr/task_fetch_accounts.go b/internal/app/connectors/modulr/task_fetch_accounts.go index 49372eba..62af588b 100644 --- a/internal/app/connectors/modulr/task_fetch_accounts.go +++ b/internal/app/connectors/modulr/task_fetch_accounts.go @@ -8,10 +8,10 @@ import ( "github.com/formancehq/payments/internal/app/connectors/modulr/client" "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) -func taskFetchAccounts(logger sharedlogging.Logger, client *client.Client) task.Task { +func taskFetchAccounts(logger logging.Logger, client *client.Client) task.Task { return func( ctx context.Context, scheduler task.Scheduler, diff --git a/internal/app/connectors/modulr/task_fetch_transactions.go b/internal/app/connectors/modulr/task_fetch_transactions.go index 45974bad..d767ccf6 100644 --- a/internal/app/connectors/modulr/task_fetch_transactions.go +++ b/internal/app/connectors/modulr/task_fetch_transactions.go @@ -12,10 +12,10 @@ import ( "github.com/formancehq/payments/internal/app/ingestion" "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) -func taskFetchTransactions(logger sharedlogging.Logger, client *client.Client, accountID string) task.Task { +func taskFetchTransactions(logger logging.Logger, client *client.Client, accountID string) task.Task { return func( ctx context.Context, ingester ingestion.Ingester, diff --git a/internal/app/connectors/modulr/task_resolve.go b/internal/app/connectors/modulr/task_resolve.go index 5ae660ee..121cb99f 100644 --- a/internal/app/connectors/modulr/task_resolve.go +++ b/internal/app/connectors/modulr/task_resolve.go @@ -6,7 +6,7 @@ import ( "github.com/formancehq/payments/internal/app/connectors/modulr/client" "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) const ( @@ -21,7 +21,7 @@ type TaskDescriptor struct { AccountID string `json:"accountID" yaml:"accountID" bson:"accountID"` } -func resolveTasks(logger sharedlogging.Logger, config Config) func(taskDefinition TaskDescriptor) task.Task { +func resolveTasks(logger logging.Logger, config Config) func(taskDefinition TaskDescriptor) task.Task { modulrClient, err := client.NewClient(config.APIKey, config.APISecret, config.Endpoint) if err != nil { return func(taskDefinition TaskDescriptor) task.Task { diff --git a/internal/app/connectors/stripe/connector.go b/internal/app/connectors/stripe/connector.go index 9b60be0e..06596c0b 100644 --- a/internal/app/connectors/stripe/connector.go +++ b/internal/app/connectors/stripe/connector.go @@ -8,13 +8,13 @@ import ( "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) const Name = models.ConnectorProviderStripe type Connector struct { - logger sharedlogging.Logger + logger logging.Logger cfg Config } @@ -49,7 +49,7 @@ func (c *Connector) Resolve(descriptor models.TaskDescriptor) task.Task { var _ integration.Connector = &Connector{} -func newConnector(logger sharedlogging.Logger, cfg Config) *Connector { +func newConnector(logger logging.Logger, cfg Config) *Connector { return &Connector{ logger: logger.WithFields(map[string]any{ "component": "connector", diff --git a/internal/app/connectors/stripe/loader.go b/internal/app/connectors/stripe/loader.go index bccf050b..5bdeab4d 100644 --- a/internal/app/connectors/stripe/loader.go +++ b/internal/app/connectors/stripe/loader.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/connectors" "github.com/formancehq/payments/internal/app/integration" ) @@ -22,7 +22,7 @@ func (l *Loader) Name() models.ConnectorProvider { return Name } -func (l *Loader) Load(logger sharedlogging.Logger, config Config) integration.Connector { +func (l *Loader) Load(logger logging.Logger, config Config) integration.Connector { return newConnector(logger, config) } diff --git a/internal/app/connectors/stripe/runner.go b/internal/app/connectors/stripe/runner.go index 82578bcc..0833f73c 100644 --- a/internal/app/connectors/stripe/runner.go +++ b/internal/app/connectors/stripe/runner.go @@ -4,11 +4,11 @@ import ( "context" "time" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) func NewRunner( - logger sharedlogging.Logger, + logger logging.Logger, trigger *TimelineTrigger, pollingPeriod time.Duration, ) *Runner { @@ -25,7 +25,7 @@ func NewRunner( type Runner struct { stopChan chan chan struct{} trigger *TimelineTrigger - logger sharedlogging.Logger + logger logging.Logger pollingPeriod time.Duration } diff --git a/internal/app/connectors/stripe/runner_test.go b/internal/app/connectors/stripe/runner_test.go index 78a65a8c..13a556fd 100644 --- a/internal/app/connectors/stripe/runner_test.go +++ b/internal/app/connectors/stripe/runner_test.go @@ -7,7 +7,7 @@ import ( "github.com/stripe/stripe-go/v72" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/stretchr/testify/require" ) @@ -28,7 +28,7 @@ func TestStopTailing(t *testing.T) { MoreRecentID: "tx2", }) - logger := sharedlogging.GetLogger(context.Background()) + logger := logging.GetLogger(context.Background()) trigger := NewTimelineTrigger(logger, NoOpIngester, timeline) r := NewRunner(logger, trigger, time.Second) diff --git a/internal/app/connectors/stripe/task_connected_account.go b/internal/app/connectors/stripe/task_connected_account.go index 7d10667c..95cc1035 100644 --- a/internal/app/connectors/stripe/task_connected_account.go +++ b/internal/app/connectors/stripe/task_connected_account.go @@ -3,13 +3,13 @@ package stripe import ( "context" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/ingestion" "github.com/formancehq/payments/internal/app/task" "github.com/stripe/stripe-go/v72" ) -func ingestBatch(ctx context.Context, logger sharedlogging.Logger, ingester ingestion.Ingester, +func ingestBatch(ctx context.Context, logger logging.Logger, ingester ingestion.Ingester, bts []*stripe.BalanceTransaction, commitState TimelineState, tail bool, ) error { batch := ingestion.PaymentBatch{} @@ -42,9 +42,9 @@ func ingestBatch(ctx context.Context, logger sharedlogging.Logger, ingester inge return nil } -func ConnectedAccountTask(config Config, account string) func(ctx context.Context, logger sharedlogging.Logger, +func ConnectedAccountTask(config Config, account string) func(ctx context.Context, logger logging.Logger, ingester ingestion.Ingester, resolver task.StateResolver) error { - return func(ctx context.Context, logger sharedlogging.Logger, ingester ingestion.Ingester, + return func(ctx context.Context, logger logging.Logger, ingester ingestion.Ingester, resolver task.StateResolver, ) error { logger.Infof("Create new trigger") diff --git a/internal/app/connectors/stripe/task_main.go b/internal/app/connectors/stripe/task_main.go index 3273bd98..2d496fe3 100644 --- a/internal/app/connectors/stripe/task_main.go +++ b/internal/app/connectors/stripe/task_main.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/ingestion" "github.com/formancehq/payments/internal/app/task" "github.com/pkg/errors" @@ -14,7 +14,7 @@ import ( func ingest( ctx context.Context, - logger sharedlogging.Logger, + logger logging.Logger, scheduler task.Scheduler, ingester ingestion.Ingester, bts []*stripe.BalanceTransaction, @@ -52,9 +52,9 @@ func ingest( return nil } -func MainTask(config Config) func(ctx context.Context, logger sharedlogging.Logger, resolver task.StateResolver, +func MainTask(config Config) func(ctx context.Context, logger logging.Logger, resolver task.StateResolver, scheduler task.Scheduler, ingester ingestion.Ingester) error { - return func(ctx context.Context, logger sharedlogging.Logger, resolver task.StateResolver, + return func(ctx context.Context, logger logging.Logger, resolver task.StateResolver, scheduler task.Scheduler, ingester ingestion.Ingester, ) error { runner := NewRunner( diff --git a/internal/app/connectors/stripe/timeline_trigger.go b/internal/app/connectors/stripe/timeline_trigger.go index d002b9fd..f930acc8 100644 --- a/internal/app/connectors/stripe/timeline_trigger.go +++ b/internal/app/connectors/stripe/timeline_trigger.go @@ -3,14 +3,14 @@ package stripe import ( "context" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/pkg/errors" "github.com/stripe/stripe-go/v72" "golang.org/x/sync/semaphore" ) func NewTimelineTrigger( - logger sharedlogging.Logger, + logger logging.Logger, ingester Ingester, timeline *Timeline, ) *TimelineTrigger { @@ -25,7 +25,7 @@ func NewTimelineTrigger( } type TimelineTrigger struct { - logger sharedlogging.Logger + logger logging.Logger ingester Ingester timeline *Timeline sem *semaphore.Weighted diff --git a/internal/app/connectors/stripe/timeline_trigger_test.go b/internal/app/connectors/stripe/timeline_trigger_test.go index 57d57375..9292272f 100644 --- a/internal/app/connectors/stripe/timeline_trigger_test.go +++ b/internal/app/connectors/stripe/timeline_trigger_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/stretchr/testify/require" "github.com/stripe/stripe-go/v72" ) @@ -24,7 +24,7 @@ func TestTimelineTrigger(t *testing.T) { ingestedTx := make([]*stripe.BalanceTransaction, 0) trigger := NewTimelineTrigger( - sharedlogging.GetLogger(context.Background()), + logging.GetLogger(context.Background()), IngesterFn(func(ctx context.Context, batch []*stripe.BalanceTransaction, commitState TimelineState, tail bool) error { ingestedTx = append(ingestedTx, batch...) @@ -73,7 +73,7 @@ func TestCancelTimelineTrigger(t *testing.T) { waiting := make(chan struct{}) trigger := NewTimelineTrigger( - sharedlogging.GetLogger(context.Background()), + logging.GetLogger(context.Background()), IngesterFn(func(ctx context.Context, batch []*stripe.BalanceTransaction, commitState TimelineState, tail bool) error { close(waiting) // Instruct the test the trigger is in fetching state <-ctx.Done() diff --git a/internal/app/connectors/stripe/utils_test.go b/internal/app/connectors/stripe/utils_test.go index e17eed6d..6ebcc49a 100644 --- a/internal/app/connectors/stripe/utils_test.go +++ b/internal/app/connectors/stripe/utils_test.go @@ -13,8 +13,8 @@ import ( "github.com/formancehq/payments/internal/pkg/fifo" - "github.com/formancehq/go-libs/sharedlogging" - "github.com/formancehq/go-libs/sharedlogging/sharedlogginglogrus" + "github.com/formancehq/go-libs/logging" + "github.com/formancehq/go-libs/logging/logginglogrus" "github.com/sirupsen/logrus" "github.com/stripe/stripe-go/v72" ) @@ -25,7 +25,7 @@ func TestMain(m *testing.M) { if testing.Verbose() { l := logrus.New() l.Level = logrus.DebugLevel - sharedlogging.SetFactory(sharedlogging.StaticLoggerFactory(sharedlogginglogrus.New(l))) + logging.SetFactory(logging.StaticLoggerFactory(logginglogrus.New(l))) } os.Exit(m.Run()) diff --git a/internal/app/connectors/wise/connector.go b/internal/app/connectors/wise/connector.go index 8881c280..ab71883b 100644 --- a/internal/app/connectors/wise/connector.go +++ b/internal/app/connectors/wise/connector.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/task" ) @@ -13,7 +13,7 @@ import ( const Name = models.ConnectorProviderWise type Connector struct { - logger sharedlogging.Logger + logger logging.Logger cfg Config } @@ -44,7 +44,7 @@ func (c *Connector) Resolve(descriptor models.TaskDescriptor) task.Task { var _ integration.Connector = &Connector{} -func newConnector(logger sharedlogging.Logger, cfg Config) *Connector { +func newConnector(logger logging.Logger, cfg Config) *Connector { return &Connector{ logger: logger.WithFields(map[string]any{ "component": "connector", diff --git a/internal/app/connectors/wise/loader.go b/internal/app/connectors/wise/loader.go index f23bde4f..ee45ab29 100644 --- a/internal/app/connectors/wise/loader.go +++ b/internal/app/connectors/wise/loader.go @@ -1,7 +1,7 @@ package wise import ( - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/integration" "github.com/formancehq/payments/internal/app/models" ) @@ -18,7 +18,7 @@ func (l *Loader) Name() models.ConnectorProvider { return Name } -func (l *Loader) Load(logger sharedlogging.Logger, config Config) integration.Connector { +func (l *Loader) Load(logger logging.Logger, config Config) integration.Connector { return newConnector(logger, config) } diff --git a/internal/app/connectors/wise/task_fetch_profiles.go b/internal/app/connectors/wise/task_fetch_profiles.go index 07eb8f75..01506762 100644 --- a/internal/app/connectors/wise/task_fetch_profiles.go +++ b/internal/app/connectors/wise/task_fetch_profiles.go @@ -8,10 +8,10 @@ import ( "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) -func taskFetchProfiles(logger sharedlogging.Logger, client *client) task.Task { +func taskFetchProfiles(logger logging.Logger, client *client) task.Task { return func( ctx context.Context, scheduler task.Scheduler, diff --git a/internal/app/connectors/wise/task_fetch_transfers.go b/internal/app/connectors/wise/task_fetch_transfers.go index 1c1200d2..58c2e433 100644 --- a/internal/app/connectors/wise/task_fetch_transfers.go +++ b/internal/app/connectors/wise/task_fetch_transfers.go @@ -8,12 +8,12 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/ingestion" "github.com/formancehq/payments/internal/app/task" ) -func taskFetchTransfers(logger sharedlogging.Logger, client *client, profileID uint64) task.Task { +func taskFetchTransfers(logger logging.Logger, client *client, profileID uint64) task.Task { return func( ctx context.Context, scheduler task.Scheduler, diff --git a/internal/app/connectors/wise/task_resolve.go b/internal/app/connectors/wise/task_resolve.go index 738d4ed4..4d7b7e34 100644 --- a/internal/app/connectors/wise/task_resolve.go +++ b/internal/app/connectors/wise/task_resolve.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" ) const ( @@ -20,7 +20,7 @@ type TaskDescriptor struct { ProfileID uint64 `json:"profileID" yaml:"profileID" bson:"profileID"` } -func resolveTasks(logger sharedlogging.Logger, config Config) func(taskDefinition TaskDescriptor) task.Task { +func resolveTasks(logger logging.Logger, config Config) func(taskDefinition TaskDescriptor) task.Task { client := newClient(config.APIKey) return func(taskDefinition TaskDescriptor) task.Task { diff --git a/internal/app/ingestion/ingester.go b/internal/app/ingestion/ingester.go index f3ebe198..1bf9ca0f 100644 --- a/internal/app/ingestion/ingester.go +++ b/internal/app/ingestion/ingester.go @@ -4,8 +4,8 @@ import ( "context" "encoding/json" - "github.com/formancehq/go-libs/sharedlogging" - "github.com/formancehq/go-libs/sharedpublish" + "github.com/formancehq/go-libs/logging" + "github.com/formancehq/go-libs/publish" "github.com/formancehq/payments/internal/app/models" ) @@ -16,10 +16,10 @@ type Ingester interface { type DefaultIngester struct { repo Repository - logger sharedlogging.Logger + logger logging.Logger provider models.ConnectorProvider descriptor models.TaskDescriptor - publisher sharedpublish.Publisher + publisher publish.Publisher } type Repository interface { @@ -32,8 +32,8 @@ func NewDefaultIngester( provider models.ConnectorProvider, descriptor models.TaskDescriptor, repo Repository, - logger sharedlogging.Logger, - publisher sharedpublish.Publisher, + logger logging.Logger, + publisher publish.Publisher, ) *DefaultIngester { return &DefaultIngester{ provider: provider, diff --git a/internal/app/integration/loader.go b/internal/app/integration/loader.go index 8b0b9944..519aa6c6 100644 --- a/internal/app/integration/loader.go +++ b/internal/app/integration/loader.go @@ -1,13 +1,13 @@ package integration import ( - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/models" ) type Loader[ConnectorConfig models.ConnectorConfigObject] interface { Name() models.ConnectorProvider - Load(logger sharedlogging.Logger, config ConnectorConfig) Connector + Load(logger logging.Logger, config ConnectorConfig) Connector // ApplyDefaults is used to fill default values of the provided configuration object ApplyDefaults(t ConnectorConfig) ConnectorConfig @@ -19,13 +19,13 @@ type Loader[ConnectorConfig models.ConnectorConfigObject] interface { } type LoaderBuilder[ConnectorConfig models.ConnectorConfigObject] struct { - loadFunction func(logger sharedlogging.Logger, config ConnectorConfig) Connector + loadFunction func(logger logging.Logger, config ConnectorConfig) Connector applyDefaults func(t ConnectorConfig) ConnectorConfig name models.ConnectorProvider allowedTasks int } -func (b *LoaderBuilder[ConnectorConfig]) WithLoad(loadFunction func(logger sharedlogging.Logger, +func (b *LoaderBuilder[ConnectorConfig]) WithLoad(loadFunction func(logger logging.Logger, config ConnectorConfig) Connector, ) *LoaderBuilder[ConnectorConfig] { b.loadFunction = loadFunction @@ -64,7 +64,7 @@ func NewLoaderBuilder[ConnectorConfig models.ConnectorConfigObject](name models. } type BuiltLoader[ConnectorConfig models.ConnectorConfigObject] struct { - loadFunction func(logger sharedlogging.Logger, config ConnectorConfig) Connector + loadFunction func(logger logging.Logger, config ConnectorConfig) Connector applyDefaults func(t ConnectorConfig) ConnectorConfig name models.ConnectorProvider allowedTasks int @@ -78,7 +78,7 @@ func (b *BuiltLoader[ConnectorConfig]) Name() models.ConnectorProvider { return b.name } -func (b *BuiltLoader[ConnectorConfig]) Load(logger sharedlogging.Logger, config ConnectorConfig) Connector { +func (b *BuiltLoader[ConnectorConfig]) Load(logger logging.Logger, config ConnectorConfig) Connector { if b.loadFunction != nil { return b.loadFunction(logger, config) } diff --git a/internal/app/integration/manager.go b/internal/app/integration/manager.go index f1c5f312..4e7c1d36 100644 --- a/internal/app/integration/manager.go +++ b/internal/app/integration/manager.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/payments/internal/app/messages" - "github.com/formancehq/go-libs/sharedpublish" + "github.com/formancehq/go-libs/publish" "github.com/formancehq/payments/internal/app/storage" @@ -13,7 +13,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/payments/internal/app/task" "github.com/pkg/errors" ) @@ -27,13 +27,13 @@ var ( ) type ConnectorManager[Config models.ConnectorConfigObject] struct { - logger sharedlogging.Logger + logger logging.Logger loader Loader[Config] connector Connector store Repository schedulerFactory TaskSchedulerFactory scheduler *task.DefaultTaskScheduler - publisher sharedpublish.Publisher + publisher publish.Publisher } func (l *ConnectorManager[ConnectorConfig]) Enable(ctx context.Context) error { @@ -256,11 +256,11 @@ func (l *ConnectorManager[ConnectorConfig]) Reset(ctx context.Context) error { } func NewConnectorManager[ConnectorConfig models.ConnectorConfigObject]( - logger sharedlogging.Logger, + logger logging.Logger, store Repository, loader Loader[ConnectorConfig], schedulerFactory TaskSchedulerFactory, - publisher sharedpublish.Publisher, + publisher publish.Publisher, ) *ConnectorManager[ConnectorConfig] { return &ConnectorManager[ConnectorConfig]{ logger: logger.WithFields(map[string]interface{}{ diff --git a/internal/app/integration/manager_test.go b/internal/app/integration/manager_test.go index 6ced6a22..08620215 100644 --- a/internal/app/integration/manager_test.go +++ b/internal/app/integration/manager_test.go @@ -12,8 +12,8 @@ import ( "github.com/formancehq/payments/internal/app/task" - "github.com/formancehq/go-libs/sharedlogging" - "github.com/formancehq/go-libs/sharedlogging/sharedlogginglogrus" + "github.com/formancehq/go-libs/logging" + "github.com/formancehq/go-libs/logging/logginglogrus" "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" ) @@ -47,7 +47,7 @@ func withManager[ConnectorConfig models.ConnectorConfigObject](builder *Connecto return dig.New(), nil }) - logger := sharedlogginglogrus.New(l) + logger := logginglogrus.New(l) taskStore := task.NewInMemoryStore() managerStore := NewInMemoryStore() provider := models.ConnectorProvider(uuid.New().String()) @@ -59,7 +59,7 @@ func withManager[ConnectorConfig models.ConnectorConfigObject](builder *Connecto }) loader := NewLoaderBuilder[ConnectorConfig](provider). - WithLoad(func(logger sharedlogging.Logger, config ConnectorConfig) Connector { + WithLoad(func(logger logging.Logger, config ConnectorConfig) Connector { return builder.Build() }). WithAllowedTasks(1). diff --git a/internal/app/storage/module.go b/internal/app/storage/module.go index 47060d6b..eb82307a 100644 --- a/internal/app/storage/module.go +++ b/internal/app/storage/module.go @@ -14,7 +14,7 @@ import ( "github.com/uptrace/bun" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "go.uber.org/fx" ) @@ -46,7 +46,7 @@ func Module(uri string) fx.Option { fx.Invoke(func(lc fx.Lifecycle, repo *Storage) { lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error { - sharedlogging.Debug("Ping database...") + logging.Debug("Ping database...") // TODO: Check migrations state and panic if migrations are not applied diff --git a/internal/app/task/scheduler.go b/internal/app/task/scheduler.go index 36cd6996..82fe9900 100644 --- a/internal/app/task/scheduler.go +++ b/internal/app/task/scheduler.go @@ -16,7 +16,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging" + "github.com/formancehq/go-libs/logging" "github.com/pkg/errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -35,7 +35,7 @@ type Scheduler interface { type taskHolder struct { descriptor models.TaskDescriptor cancel func() - logger sharedlogging.Logger + logger logging.Logger stopChan StopChan } @@ -43,7 +43,7 @@ type ContainerCreateFunc func(ctx context.Context, descriptor models.TaskDescrip type DefaultTaskScheduler struct { provider models.ConnectorProvider - logger sharedlogging.Logger + logger logging.Logger store Repository containerFactory ContainerCreateFunc tasks map[string]*taskHolder @@ -192,21 +192,21 @@ func (s *DefaultTaskScheduler) deleteTask(holder *taskHolder) { return } - sharedlogging.Error(err) + logging.Error(err) return } p := s.resolver.Resolve(oldestPendingTask.GetDescriptor()) if p == nil { - sharedlogging.Errorf("unable to resolve task") + logging.Errorf("unable to resolve task") return } err = s.startTask(oldestPendingTask.GetDescriptor()) if err != nil { - sharedlogging.Error(err) + logging.Error(err) } } @@ -272,7 +272,7 @@ func (s *DefaultTaskScheduler) startTask(descriptor models.TaskDescriptor) error panic(err) } - err = container.Provide(func() sharedlogging.Logger { + err = container.Provide(func() logging.Logger { return s.logger }) if err != nil { @@ -346,7 +346,7 @@ var _ Scheduler = &DefaultTaskScheduler{} func NewDefaultScheduler( provider models.ConnectorProvider, - logger sharedlogging.Logger, + logger logging.Logger, store Repository, containerFactory ContainerCreateFunc, resolver Resolver, diff --git a/internal/app/task/scheduler_test.go b/internal/app/task/scheduler_test.go index 4a88f9e7..4e92b011 100644 --- a/internal/app/task/scheduler_test.go +++ b/internal/app/task/scheduler_test.go @@ -12,7 +12,7 @@ import ( "github.com/formancehq/payments/internal/app/models" - "github.com/formancehq/go-libs/sharedlogging/sharedlogginglogrus" + "github.com/formancehq/go-libs/logging/logginglogrus" "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" ) @@ -67,7 +67,7 @@ func TestTaskScheduler(t *testing.T) { l.SetLevel(logrus.DebugLevel) } - logger := sharedlogginglogrus.New(l) + logger := logginglogrus.New(l) t.Run("Nominal", func(t *testing.T) { t.Parallel()