-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
50 lines (43 loc) · 1.08 KB
/
options.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package sol
import "strings"
// Common options
const (
OmitEmpty = "omitempty" // Skip this field if it has a zero value
OmitUpdate = "omitupdate" // Skip this field during updates
)
type options []string
// Equals tests equality - order matters
func (o options) Equals(other options) bool {
if len(o) != len(other) {
return false
}
for i, opt := range other {
if opt != other[i] {
return false
}
}
return true
}
// Has returns true if the given options exists in the current options
func (o options) Has(option string) bool {
for _, opt := range o {
if opt == option {
return true
}
}
return false
}
// parseTag splits a DB struct tag into its name and options
func parseTag(tag string) (string, options) {
parts := strings.Split(tag, ",")
return parts[0], options(parts[1:])
}
// splitName separates the tag into table and column names.
// If no separator (.) is given, assume the name is column only.
func splitName(name string) (string, string) {
parts := strings.SplitN(name, ".", 2)
if len(parts) > 1 {
return parts[0], parts[1]
}
return "", parts[0]
}