forked from frodenas/gcs-resource
/
models.go
40 lines (32 loc) · 851 Bytes
/
models.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
package gcsresource
import "strconv"
type Source struct {
JSONKey string `json:"json_key"`
Bucket string `json:"bucket"`
Regexp string `json:"regexp"`
VersionedFile string `json:"versioned_file"`
}
func (source Source) IsValid() (bool, string) {
if source.Bucket == "" {
return false, "please specify the bucket"
}
if source.Regexp != "" && source.VersionedFile != "" {
return false, "please specify either regexp or versioned_file"
}
return true, ""
}
type Version struct {
Path string `json:"path,omitempty"`
Generation string `json:"generation,omitempty"`
}
func (v Version) GenerationValue() (int64, error) {
i, err := strconv.ParseInt(v.Generation, 10, 64)
if err != nil {
return 0, err
}
return i, nil
}
type MetadataPair struct {
Name string `json:"name"`
Value string `json:"value"`
}