-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.go
49 lines (42 loc) · 1.35 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
package gortb
import (
"errors"
)
// Validation errors for App
var (
ErrMissingAppID = errors.New("app missing required ID")
ErrInvalidPrivacyPolicy = errors.New("app privacy policy must be 0 or 1")
ErrInvalidPaid = errors.New("app paid field must be 0 or 1")
)
type App struct {
ID string `json:"id" binding:"required"`
Name string `json:"name,omitempty"`
Bundle string `json:"bundle,omitempty"`
Domain string `json:"domain,omitempty"`
StoreURL string `json:"storeurl,omitempty"`
Cat []string `json:"cat,omitempty"`
SectionCat []string `json:"sectioncat,omitempty"`
PageCat []string `json:"pagecat,omitempty"`
Ver string `json:"ver,omitempty"`
PrivacyPolicy int `json:"privacypolicy,omitempty"`
Paid int `json:"paid,omitempty"`
Publisher *Publisher `json:"publisher,omitempty"`
Content *Content `json:"content,omitempty"`
Keywords string `json:"keywords,omitempty"`
Ext interface{} `json:"ext,omitempty"`
}
func (a *App) Validate() error {
// Check required fields
if a.ID == "" {
return ErrMissingAppID
}
// Validate privacy policy field
if a.PrivacyPolicy != 0 && a.PrivacyPolicy != 1 {
return ErrInvalidPrivacyPolicy
}
// Validate paid field
if a.Paid != 0 && a.Paid != 1 {
return ErrInvalidPaid
}
return nil
}