diff --git a/config.yaml b/config.yaml index 340c229..35fe99c 100644 --- a/config.yaml +++ b/config.yaml @@ -8,6 +8,11 @@ db: listener: addr: :8000 +# Routing config is used for deploying several service instances under one domain to differentiate them +# by configurable prefix. Note that prefix should be formatted as `/integrations/configured-service-prefix/` +routing: + prefix: "/integrations/configured-service-prefix/" + airdrop: amount: amount # amount in natural numbers (1, 2, 10 etc.) decimals part is taken directly from the contract token_address: erc20_token_address diff --git a/internal/config/main.go b/internal/config/main.go index 5d60d80..814ab67 100644 --- a/internal/config/main.go +++ b/internal/config/main.go @@ -18,6 +18,7 @@ type Config struct { airdrop comfig.Once verifier comfig.Once + routing comfig.Once getter kv.Getter } diff --git a/internal/config/routing.go b/internal/config/routing.go new file mode 100644 index 0000000..ab19c76 --- /dev/null +++ b/internal/config/routing.go @@ -0,0 +1,29 @@ +package config + +import ( + "gitlab.com/distributed_lab/figure/v3" + "gitlab.com/distributed_lab/kit/kv" + "gitlab.com/distributed_lab/logan/v3" + "gitlab.com/distributed_lab/logan/v3/errors" +) + +const routingYamlKey = "routing" + +type Routing struct { + Prefix string `fig:"prefix,required"` +} + +func (c *Config) NewRouting() Routing { + return c.routing.Do(func() interface{} { + var cfg Routing + + err := figure.Out(&cfg). + From(kv.MustGetStringMap(c.getter, routingYamlKey)). + Please() + if err != nil { + panic(errors.Wrap(err, "failed to figure out config", logan.F{"key": routingYamlKey})) + } + + return cfg + }).(Routing) +} diff --git a/internal/service/router.go b/internal/service/router.go index 4ef8e15..5aab711 100644 --- a/internal/service/router.go +++ b/internal/service/router.go @@ -42,8 +42,7 @@ func Run(ctx context.Context, cfg *config.Config) { ), handlers.DBCloneMiddleware(cfg.DB()), ) - - r.Route("/integrations/evm-airdrop-svc", func(r chi.Router) { + r.Route(cfg.NewRouting().Prefix, func(r chi.Router) { r.Route("/airdrops", func(r chi.Router) { r.Post("/", handlers.CreateAirdrop) r.Get("/{nullifier}", handlers.GetAirdrop)