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.

33 lines
710 B

4 years ago
package key
import (
"context"
"strings"
"gitoa.ru/go-4devs/config"
)
func LastIndex(sep string, factory config.KeyFactory) func(ctx context.Context, key config.Key) (string, string) {
return func(ctx context.Context, key config.Key) (string, string) {
name := factory(ctx, key)
4 years ago
idx := strings.LastIndex(name, sep)
4 years ago
if idx == -1 {
return name, ""
4 years ago
}
return name[0:idx], name[idx+len(sep):]
4 years ago
}
}
func LastIndexField(sep, def string, factory config.KeyFactory) func(ctx context.Context, key config.Key) (string, string) {
return func(ctx context.Context, key config.Key) (string, string) {
p, k := LastIndex(sep, factory)(ctx, key)
if k == "" {
return p, def
}
return p, k
}
}