Rename the config structs setDefaults to validate

This allows us to check for some required values and give an easy to respond
to error at startup rather than a lot of validation during run time.
This commit is contained in:
Gary Kramlich
2021-11-19 16:53:43 -06:00
parent 8553f49ac6
commit 2b63ddc6b8
5 changed files with 52 additions and 16 deletions

View File

@@ -1,8 +1,6 @@
package config
import (
"fmt"
"bytes"
"text/template"
)
@@ -13,7 +11,7 @@ type bridge struct {
usernameTemplate *template.Template `yaml:"-"`
}
func (b *bridge) setDefaults() error {
func (b *bridge) validate() error {
var err error
if b.UsernameTemplate == "" {
@@ -40,14 +38,12 @@ func (b *bridge) UnmarshalYAML(unmarshal func(interface{}) error) error {
*b = bridge(raw)
return b.setDefaults()
return b.validate()
}
func (b bridge) FormatUsername(userid string) string {
var buffer bytes.Buffer
fmt.Printf("bridge: %#v\n", b)
b.usernameTemplate.Execute(&buffer, userid)
return buffer.String()