You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
4 years ago
|
package key
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"strings"
|
||
|
|
||
|
"gitoa.ru/go-4devs/config"
|
||
|
)
|
||
|
|
||
|
func NsAppName(sep string) config.KeyFactory {
|
||
|
return func(_ context.Context, key config.Key) string {
|
||
|
return strings.Join([]string{key.Namespace, key.AppName, key.Name}, sep)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func AppName(sep string) config.KeyFactory {
|
||
|
return func(_ context.Context, key config.Key) string {
|
||
|
return strings.Join([]string{key.AppName, key.Name}, sep)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func PrefixName(prefix string, factory config.KeyFactory) config.KeyFactory {
|
||
|
return func(ctx context.Context, key config.Key) string {
|
||
|
return prefix + factory(ctx, key)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Name(_ context.Context, key config.Key) string {
|
||
|
return key.Name
|
||
|
}
|
||
|
|
||
|
func AliasName(name string, alias string, def config.KeyFactory) config.KeyFactory {
|
||
|
return func(ctx context.Context, key config.Key) string {
|
||
|
if name == key.Name {
|
||
|
return alias
|
||
|
}
|
||
|
|
||
|
return def(ctx, key)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func ReplaceAll(oldVal, newVal string, parent config.KeyFactory) config.KeyFactory {
|
||
|
return func(ctx context.Context, key config.Key) string {
|
||
|
return strings.ReplaceAll(parent(ctx, key), oldVal, newVal)
|
||
|
}
|
||
|
}
|