Add a generate-registration command

This commit is contained in:
Gary Kramlich
2021-11-18 02:44:21 -06:00
parent 5b3811ce96
commit 09911a11e3
10 changed files with 229 additions and 2 deletions

40
config/bridge.go Normal file
View File

@@ -0,0 +1,40 @@
package config
import (
"bytes"
"text/template"
)
type bridge struct {
UsernameTemplate string `yaml:"username_template"`
usernameTemplate *template.Template `yaml:"-"`
}
func (b *bridge) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawBridge bridge
raw := rawBridge{}
err := unmarshal(&raw)
if err != nil {
return err
}
raw.usernameTemplate, err = template.New("username").Parse(raw.UsernameTemplate)
if err != nil {
return err
}
*b = bridge(raw)
return nil
}
func (b bridge) FormatUsername(userid string) string {
var buffer bytes.Buffer
b.usernameTemplate.Execute(&buffer, userid)
return buffer.String()
}