MCPcopy Create free account
hub / github.com/AdRoll/baker / fillDefaults

Method fillDefaults

filter/external_match.go:55–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53}
54
55func (cfg *ExternalMatchConfig) fillDefaults() error {
56 if cfg.Region == "" {
57 cfg.Region = "us-west-2"
58 }
59
60 // Check that Files and DateTimeLayout are coherent.
61 for _, u := range cfg.Files {
62 isFormatted := strings.Contains(u, "%s")
63 if isFormatted != (cfg.DateTimeLayout != "") {
64 if cfg.DateTimeLayout != "" {
65 return errors.New("DateTimeLayout is valid only if all strings in Files contain %s")
66 }
67 return errors.New("strings in Files may only contain %s if DateTimeLayout is set")
68 }
69 }
70
71 // Check that TimeSubtract and DateTimeLayout are coherent.
72 if (cfg.TimeSubtract != 0) && cfg.DateTimeLayout == "" {
73 return errors.New("TimeSubtract is only valid if DateTimeLayout is set")
74 }
75
76 // Validate URLs
77 for _, u := range cfg.evaluateURLs() {
78 parsed, err := url.Parse(u)
79 if err != nil {
80 return err
81 }
82 switch parsed.Scheme {
83 case "s3", "s3n", "file":
84 default:
85 return fmt.Errorf("%s: unsupported scheme %s", u, parsed.Scheme)
86 }
87 }
88
89 if cfg.CSVColumn < 0 {
90 return errors.New("negative CSVColumn")
91 }
92
93 return nil
94}
95
96// evaluateURLs evaluates urls using the current configuration..
97func (cfg *ExternalMatchConfig) evaluateURLs() []string {

Callers 1

NewExternalMatchFunction · 0.45

Calls 2

evaluateURLsMethod · 0.95
ParseMethod · 0.65

Tested by

no test coverage detected