openmeter / app /config /apps.go
Leon4gr45's picture
Upload folder using huggingface_hub (part 4)
1f10f31 verified
Raw
History Blame Contribute Delete
1.36 kB
package config
import (
"errors"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
type AppsConfiguration struct {
// BaseURL is the base URL for the Stripe webhook.
BaseURL string `yaml:"baseURL"`
Stripe AppStripeConfiguration `yaml:"stripe"`
}
func (c AppsConfiguration) Validate() error {
var errs []error
if c.BaseURL == "" {
errs = append(errs, errors.New("base URL is required"))
}
if err := c.Stripe.Validate(); err != nil {
errs = append(errs, err)
}
return errors.Join(errs...)
}
type AppStripeConfiguration struct {
DisableWebhookRegistration bool `yaml:"disableWebhookRegistration"`
WebhookURLPattern string `yaml:"webhookURLPattern" mapstructure:"webhookURLPattern"`
}
func (c AppStripeConfiguration) Validate() error {
return nil
}
func ConfigureApps(v *viper.Viper, flags *pflag.FlagSet) {
v.SetDefault("apps.baseURL", "https://example.com")
flags.Bool("stripe-disable-webhook-registration", false, "Disable webhook registration for Stripe [for local development]")
flags.String("stripe-webhook-url-pattern", "", "Webhook URL pattern for Stripe [for local development]")
_ = v.BindPFlag("apps.stripe.disableWebhookRegistration", flags.Lookup("stripe-disable-webhook-registration"))
v.SetDefault("apps.stripe.disableWebhookRegistration", false)
v.SetDefault("apps.stripe.webhookURLPattern", "")
}