/
function-global.go
51 lines (39 loc) · 1.04 KB
/
function-global.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
package model
import (
"errors"
"fmt"
"github.com/vorteil/direktiv/pkg/util"
)
type GlobalFunctionDefinition struct {
Type FunctionType `yaml:"type" json:"type"`
ID string `yaml:"id" json:"id"`
KnativeService string `yaml:"service" json:"service"`
Files []FunctionFileDefinition `yaml:"files,omitempty" json:"files,omitempty"`
}
func (o *GlobalFunctionDefinition) GetID() string {
return o.ID
}
func (o *GlobalFunctionDefinition) GetType() FunctionType {
return GlobalKnativeFunctionType
}
func (o *GlobalFunctionDefinition) Validate() error {
if o == nil {
return nil
}
if o.ID == "" {
return errors.New("id required")
}
if ok := util.MatchesRegex(o.ID); !ok {
return fmt.Errorf("function id must match regex: %s", util.RegexPattern)
}
if o.KnativeService == "" {
return errors.New("service required")
}
for i, f := range o.Files {
err := f.Validate()
if err != nil {
return fmt.Errorf("function file %d: %v", i, err)
}
}
return nil
}