-
Notifications
You must be signed in to change notification settings - Fork 8
/
breadops.go
47 lines (42 loc) · 1.01 KB
/
breadops.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
package database
import (
"strings"
"github.com/grokify/simplego/type/stringsutil"
)
// BreadOps uses the BREAD acronym to store identifiers for each
// operation.
type BreadOps struct {
Name string
Browse []string
Read []string
Edit []string
Add []string
Delete []string
}
func NewBreadOps(name string) BreadOps {
return BreadOps{
Name: name,
Browse: []string{},
Read: []string{},
Edit: []string{},
Add: []string{},
Delete: []string{}}
}
func (bo *BreadOps) TrimSpace(dedupe, sort bool) {
bo.Name = strings.TrimSpace(bo.Name)
if bo.Browse != nil {
bo.Browse = stringsutil.SliceCondenseSpace(bo.Browse, dedupe, sort)
}
if bo.Read != nil {
bo.Read = stringsutil.SliceCondenseSpace(bo.Read, dedupe, sort)
}
if bo.Edit != nil {
bo.Edit = stringsutil.SliceCondenseSpace(bo.Edit, dedupe, sort)
}
if bo.Add != nil {
bo.Add = stringsutil.SliceCondenseSpace(bo.Add, dedupe, sort)
}
if bo.Delete != nil {
bo.Delete = stringsutil.SliceCondenseSpace(bo.Delete, dedupe, sort)
}
}