forked from fnproject/fn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
55 lines (50 loc) · 1.03 KB
/
app.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
51
52
53
54
55
package models
type App struct {
Name string `json:"name" db:"name"`
Config Config `json:"config,omitempty" db:"config"`
}
func (a *App) Validate() error {
if a.Name == "" {
return ErrAppsMissingName
}
if len(a.Name) > maxAppName {
return ErrAppsTooLongName
}
for _, c := range a.Name {
if (c < '0' || '9' < c) && (c < 'A' || 'Z' > c) && (c < 'a' || 'z' < c) && c != '_' && c != '-' {
return ErrAppsInvalidName
}
}
return nil
}
func (a *App) Clone() *App {
var c App
c.Name = a.Name
if a.Config != nil {
c.Config = make(Config)
for k, v := range a.Config {
c.Config[k] = v
}
}
return &c
}
// UpdateConfig adds entries from patch to a.Config, and removes entries with empty values.
func (a *App) UpdateConfig(patch Config) {
if patch != nil {
if a.Config == nil {
a.Config = make(Config)
}
for k, v := range patch {
if v == "" {
delete(a.Config, k)
} else {
a.Config[k] = v
}
}
}
}
type AppFilter struct {
Name string // prefix query TODO implemented
PerPage int
Cursor string
}