Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package monorail | |
| 6 | |
| 7 import "fmt" | |
| 8 | |
| 9 // Validate checks the message for errors. | |
| 10 func (i *IssueRef) Validate() error { | |
|
seanmccullough1
2016/06/03 18:45:33
I see. This could be annoying to do without adding
nodir
2016/06/03 18:56:12
yeah, we use this approach a lot in luci-go.
| |
| 11 if i == nil { | |
| 12 return fmt.Errorf("is nil") | |
| 13 } | |
| 14 if i.ProjectId == "" { | |
| 15 return fmt.Errorf("no projectId") | |
| 16 } | |
| 17 if i.IssueId == 0 { | |
| 18 return fmt.Errorf("no issueId") | |
| 19 } | |
| 20 return nil | |
| 21 } | |
| 22 | |
| 23 // Validate checks the message for errors. | |
| 24 func (a *AtomPerson) Validate() error { | |
| 25 if a == nil { | |
| 26 return fmt.Errorf("is nil") | |
| 27 } | |
| 28 if a.Name == "" { | |
| 29 return fmt.Errorf("no name") | |
| 30 } | |
| 31 return nil | |
| 32 } | |
| 33 | |
| 34 // Validate checks the message for errors. | |
| 35 func (i *Issue) Validate() error { | |
| 36 if i == nil { | |
| 37 return fmt.Errorf("is nil") | |
| 38 } | |
| 39 if i.Status == "" { | |
| 40 return fmt.Errorf("no status") | |
| 41 } | |
| 42 for _, ref := range i.BlockedOn { | |
| 43 if err := ref.Validate(); err != nil { | |
| 44 return fmt.Errorf("blockedOn: %s", err) | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 seen := map[string]struct{}{} | |
| 49 for _, cc := range i.Cc { | |
| 50 if err := cc.Validate(); err != nil { | |
| 51 return fmt.Errorf("cc: %s", err) | |
| 52 } | |
| 53 // Monorail does not like duplicates in CC list. | |
| 54 if _, saw := seen[cc.Name]; saw { | |
| 55 return fmt.Errorf("cc: duplicate %s", cc.Name) | |
| 56 } | |
| 57 seen[cc.Name] = struct{}{} | |
| 58 } | |
| 59 | |
| 60 if i.Owner != nil { | |
| 61 if err := i.Owner.Validate(); err != nil { | |
| 62 return err | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 return nil | |
| 67 } | |
| 68 | |
| 69 // Validate checks the message for errors. | |
| 70 func (i *InsertIssueRequest) Validate() error { | |
| 71 if i.ProjectId == "" { | |
| 72 return fmt.Errorf("no projectId") | |
| 73 } | |
| 74 if err := i.Issue.Validate(); err != nil { | |
| 75 return fmt.Errorf("issue: %s", err) | |
| 76 } | |
| 77 if i.Issue.Id != 0 { | |
| 78 return fmt.Errorf("issue: must not have id") | |
| 79 } | |
| 80 return nil | |
| 81 } | |
| OLD | NEW |