Fixed server implementation and refactored

This commit is contained in:
David Allen 2024-06-20 17:09:02 -06:00
parent 0e3eec733b
commit 22195fa00a
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
8 changed files with 289 additions and 215 deletions

View file

@ -35,3 +35,20 @@ func AssertOptionsExist(params Params, opts ...string) []string {
}
return foundKeys
}
func WithDefault[T any](v T) Option {
return func(p Params) {
p["default"] = v
}
}
// Syntactic sugar generic function to get parameter from util.Params.
func Get[T any](params Params, key string, opts ...Option) *T {
if v, ok := params[key].(T); ok {
return &v
}
if defaultValue, ok := params["default"].(T); ok {
return &defaultValue
}
return nil
}