settings: allow transparent backends that don't set all values
This commit is contained in:
26
utils/strings.go
Normal file
26
utils/strings.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"maps"
|
||||
)
|
||||
|
||||
type Strings map[string]string
|
||||
|
||||
func (s Strings) set(v map[string]string) Strings {
|
||||
maps.Copy(s, v)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Strings) Get(value string) template.HTML {
|
||||
v, ok := (s)[value]
|
||||
if !ok {
|
||||
// fallback
|
||||
return template.HTML("string:" + value)
|
||||
}
|
||||
return template.HTML(v)
|
||||
}
|
||||
|
||||
func NewStrings[T ~map[string]string](v T) Strings {
|
||||
return make(Strings).set(v)
|
||||
}
|
||||
Reference in New Issue
Block a user