Files
CrimsonandGitHub deedc580e2 feat(configs): Simplify connector config definition to reduce boilerplate code (#262)
* Use validation library for dummypay config

* Replace individual connector configs with go-playground/validation struct

* Update command to compile configs.json

* Update connector template to use new validation system

* Move plugin configuration into registry and remove config.json

* Detect different types of configuration data when registering plugins

* Ensure that RegisterPlugin skips non-json fields in Config

* Update connector template to send Config struct to RegisterPlugin

* Allow omission of optional Adyen fields from config

* Add panic statements in RegisterPlugin to guard against bad plugin config setup
2025-01-17 11:14:42 +01:00

29 lines
881 B
Plaintext

package {{ .Connector }}
import (
"encoding/json"
"fmt"
"github.com/go-playground/validator/v10"
"github.com/formancehq/payments/internal/models"
)
type Config struct {
// TODO: fill Config struct
// This is the config a user will pass when installing this connector.
// Authentication criteria for connecting to your connector should be provided here. Example:
// ClientID string `json:"clientID" validate:"required"`
// APIKey string `json:"apiKey" validate:"required"`
// Endpoint string `json:"endpoint" validate:"required"`
}
func unmarshalAndValidateConfig(payload json.RawMessage) (Config, error) {
var config Config
if err := json.Unmarshal(payload, &config); err != nil {
return Config{}, fmt.Errorf("%w: %w", err, models.ErrInvalidConfig)
}
validate := validator.New(validator.WithRequiredStructEnabled())
return config, validate.Struct(config)
}