-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.go
More file actions
32 lines (29 loc) · 714 Bytes
/
helpers.go
File metadata and controls
32 lines (29 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package loadConfig
import (
"fmt"
"reflect"
"strings"
)
func isPtrToStruct(f interface{}) error {
v := reflect.ValueOf(f)
if v.Kind() != reflect.Ptr {
return fmt.Errorf("interface %s is not a pointer", v.Type().Name())
}
v = v.Elem() // element behind the ptr
if v.Kind() != reflect.Struct {
return fmt.Errorf("interface in pointer %s is not a struct", v.Type().Name())
}
return nil
}
func combineTage(lastTag, newTag string) string {
tags := []string{}
tags = append(tags, strings.Split(lastTag, ".")...)
tags = append(tags, newTag)
nonEmptyTags := []string{}
for _, t := range tags {
if t != "" {
nonEmptyTags = append(nonEmptyTags, t)
}
}
return strings.Join(nonEmptyTags, ".")
}