-
Notifications
You must be signed in to change notification settings - Fork 405
/
validator.go
60 lines (52 loc) · 1.4 KB
/
validator.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
56
57
58
59
60
package validator
import (
"context"
"io"
"github.com/fnproject/fn/api/models"
)
func NewValidator(ls models.LogStore) models.LogStore {
return &validator{ls}
}
type validator struct {
models.LogStore
}
// callID or appID will never be empty.
func (v *validator) InsertLog(ctx context.Context, call *models.Call, callLog io.Reader) error {
if call.ID == "" {
return models.ErrDatastoreEmptyCallID
}
if call.AppID == "" && call.FnID == "" {
return models.ErrMissingFnID
}
return v.LogStore.InsertLog(ctx, call, callLog)
}
// callID or appID will never be empty.
func (v *validator) GetLog(ctx context.Context, fnID, callID string) (io.Reader, error) {
if callID == "" {
return nil, models.ErrDatastoreEmptyCallID
}
if fnID == "" {
return nil, models.ErrMissingFnID
}
return v.LogStore.GetLog(ctx, fnID, callID)
}
// callID or appID will never be empty.
func (v *validator) InsertCall(ctx context.Context, call *models.Call) error {
if call.ID == "" {
return models.ErrDatastoreEmptyCallID
}
if call.FnID == "" {
return models.ErrMissingFnID
}
return v.LogStore.InsertCall(ctx, call)
}
// callID or appID will never be empty.
func (v *validator) GetCall(ctx context.Context, fnID, callID string) (*models.Call, error) {
if callID == "" {
return nil, models.ErrDatastoreEmptyCallID
}
if fnID == "" {
return nil, models.ErrMissingFnID
}
return v.LogStore.GetCall(ctx, fnID, callID)
}