-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
97 changed files
with
3,847 additions
and
3,410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fxmodules | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/formancehq/webhooks/internal/app/cache" | ||
webhookcollector "github.com/formancehq/webhooks/internal/app/webhook_collector" | ||
"github.com/formancehq/webhooks/internal/services/httpclient" | ||
storage "github.com/formancehq/webhooks/internal/services/storage/postgres" | ||
"go.uber.org/fx" | ||
) | ||
|
||
|
||
func InvokeCollector() fx.Option{ | ||
|
||
return fx.Invoke(func(lc fx.Lifecycle, | ||
database *storage.PostgresStore, | ||
cacheParams *cache.CacheParams, | ||
client *httpclient.DefaultHttpClient, | ||
) { | ||
|
||
Collector := webhookcollector.NewCollector(*cacheParams, database, client) | ||
Collector.Init() | ||
|
||
lc.Append(fx.Hook{ | ||
OnStart: func(ctx context.Context) error { | ||
Collector.Run() | ||
return nil | ||
}, | ||
OnStop: func(ctx context.Context) error { | ||
Collector.Stop() | ||
return nil | ||
}, | ||
}) | ||
|
||
|
||
}) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package fxmodules | ||
|
||
import ( | ||
|
||
"github.com/formancehq/stack/libs/go-libs/health" | ||
"github.com/formancehq/webhooks/internal/app/webhook_server/api/router" | ||
apiutils "github.com/formancehq/webhooks/internal/app/webhook_server/api/utils" | ||
httpclient "github.com/formancehq/webhooks/internal/services/httpclient" | ||
storage "github.com/formancehq/webhooks/internal/services/storage/postgres" | ||
"github.com/formancehq/stack/libs/go-libs/httpserver" | ||
|
||
"go.uber.org/fx" | ||
) | ||
|
||
func InvokeServer() fx.Option { | ||
return fx.Invoke( | ||
func( | ||
lc fx.Lifecycle, | ||
healthcontroller *health.HealthController, | ||
database *storage.PostgresStore, | ||
serverParams *apiutils.DefaultServerParams, | ||
client *httpclient.DefaultHttpClient, | ||
){ | ||
router := router.NewRouter(database, client, healthcontroller, serverParams.Auth, serverParams.Info) | ||
lc.Append(httpserver.NewHook(router, httpserver.WithAddress(serverParams.Addr))) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package fxmodules | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/formancehq/stack/libs/go-libs/auth" | ||
"github.com/formancehq/stack/libs/go-libs/logging" | ||
"github.com/formancehq/webhooks/cmd/flag" | ||
"github.com/formancehq/webhooks/internal/app/cache" | ||
apiutils "github.com/formancehq/webhooks/internal/app/webhook_server/api/utils" | ||
httpclient "github.com/formancehq/webhooks/internal/services/httpclient" | ||
storage "github.com/formancehq/webhooks/internal/services/storage/postgres" | ||
"github.com/spf13/viper" | ||
"github.com/uptrace/bun" | ||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" | ||
"go.opentelemetry.io/otel" | ||
"go.uber.org/fx" | ||
) | ||
|
||
var Tracer = otel.Tracer("webhook") | ||
|
||
func ProvideHttpClient() fx.Option { | ||
|
||
return fx.Provide( | ||
func() *httpclient.DefaultHttpClient { | ||
|
||
client := http.Client{ | ||
Transport: otelhttp.NewTransport(http.DefaultTransport), | ||
} | ||
|
||
defaultClient := httpclient.NewDefaultHttpClient(&client) | ||
|
||
return &defaultClient | ||
|
||
}, | ||
) | ||
|
||
} | ||
|
||
func ProvideCacheParams() fx.Option{ | ||
|
||
return fx.Provide( | ||
func() *cache.CacheParams { | ||
cacheParams := flag.LoadRunnerParams() | ||
return &cacheParams | ||
}, | ||
) | ||
|
||
} | ||
|
||
|
||
func ProvideDatabase() fx.Option { | ||
|
||
return fx.Provide( | ||
func(db *bun.DB) *storage.PostgresStore { | ||
database := storage.NewPostgresStoreProvider(db) | ||
return &database | ||
}, | ||
) | ||
} | ||
|
||
func ProvideServerParams () fx.Option { | ||
|
||
return fx.Provide( | ||
func(auth auth.Auth, logger logging.Logger, serviceInfo apiutils.ServiceInfo) *apiutils.DefaultServerParams { | ||
serverParams := apiutils.DefaultServerParams{} | ||
serverParams.Addr = viper.GetString(flag.Listen) | ||
serverParams.Auth = auth | ||
serverParams.Info = serviceInfo | ||
serverParams.Logger = logger | ||
|
||
return &serverParams | ||
}, | ||
) | ||
} | ||
|
||
func ProvideTopics() fx.Option{ | ||
return fx.Provide( | ||
func() []string { | ||
return viper.GetStringSlice(flag.KafkaTopics) | ||
|
||
}, | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package fxmodules | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ThreeDotsLabs/watermill/message" | ||
"github.com/formancehq/webhooks/internal/app/cache" | ||
webhookworker "github.com/formancehq/webhooks/internal/app/webhook_worker" | ||
"github.com/formancehq/webhooks/internal/services/httpclient" | ||
storage "github.com/formancehq/webhooks/internal/services/storage/postgres" | ||
"go.uber.org/fx" | ||
) | ||
|
||
|
||
|
||
func InvokeWorker() fx.Option { | ||
|
||
return fx.Invoke(func( | ||
lc fx.Lifecycle, | ||
database *storage.PostgresStore, | ||
runnerParams *cache.CacheParams, | ||
client *httpclient.DefaultHttpClient, | ||
r *message.Router, | ||
subscriber message.Subscriber, | ||
topics []string, | ||
){ | ||
|
||
Worker := webhookworker.NewWorker(*runnerParams, database, client) | ||
Worker.Init() | ||
for _, topic := range topics { | ||
r.AddNoPublisherHandler(fmt.Sprintf("messages-%s", topic), topic, subscriber, Worker.HandleMessage) | ||
|
||
} | ||
|
||
lc.Append(fx.Hook{ | ||
OnStart: func(ctx context.Context) error { | ||
|
||
return nil | ||
}, | ||
OnStop: func(ctx context.Context) error { | ||
|
||
subscriber.Close() | ||
r.Close() | ||
Worker.Stop() | ||
return nil | ||
}, | ||
}) | ||
}) | ||
|
||
} |
Oops, something went wrong.