Newer
Older
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors"
)
type Config struct {
Addresses []string `json:"addresses" doc:"List of server addresses. Requires at least one, e.g. \"https://localhost:9200\" for local testing"`
Username string `json:"username" doc:"User name for HTTP basic auth. Defaults to admin for local testing."`
Password string `json:"password" doc:"User password for HTTP basic auth. Defaults to admin for local testing."`
// TLSCertificateFilename string `json:"tls_certificate_filename" doc:"Filename to load TLS certificate. Defaults to insecure connection when not specified."`
// IndexName string `json:"index_name" doc:"OpenSearch index name should be lowercase with dashes"`
}
func (c *Config) Validate() error {
if len(c.Addresses) == 0 {
return errors.Errorf("missing addresses")
// c.Addresses = []string{"https://localhost:9200"}
}
if c.Username == "" {
c.Username = "admin"
}
if c.Password == "" {
c.Password = "admin"
}
return nil
}
const indexNamePattern = `[a-z]([a-z0-9-]*[a-z0-9])*`
var indexNameRegex = regexp.MustCompile("^" + indexNamePattern + "$")
func ValidIndexName(s string) bool {
return indexNameRegex.MatchString(s)
}