forked from mbk-lab/rui_orig
2
0
Fork 0
rui/params.go

50 lines
841 B
Go
Raw Permalink Normal View History

2021-11-17 12:32:37 +03:00
package rui
import "sort"
// Params defines a type of a parameters list
2022-07-26 18:36:00 +03:00
type Params map[string]any
2021-11-17 12:32:37 +03:00
2022-07-26 18:36:00 +03:00
func (params Params) Get(tag string) any {
2021-11-17 12:32:37 +03:00
return params.getRaw(tag)
}
2022-07-26 18:36:00 +03:00
func (params Params) getRaw(tag string) any {
2021-11-17 12:32:37 +03:00
if value, ok := params[tag]; ok {
return value
}
return nil
}
2022-07-26 18:36:00 +03:00
func (params Params) Set(tag string, value any) bool {
2021-11-17 12:32:37 +03:00
params.setRaw(tag, value)
return true
}
2022-07-26 18:36:00 +03:00
func (params Params) setRaw(tag string, value any) {
2021-11-17 12:32:37 +03:00
if value != nil {
params[tag] = value
} else {
delete(params, tag)
}
}
func (params Params) Remove(tag string) {
delete(params, tag)
}
func (params Params) Clear() {
for tag := range params {
delete(params, tag)
}
}
func (params Params) AllTags() []string {
tags := make([]string, 0, len(params))
for t := range params {
tags = append(tags, t)
}
sort.Strings(tags)
return tags
}