(links []Link)
| 125 | } |
| 126 | |
| 127 | func ValidateLinks(links []Link) error { |
| 128 | if len(links) < 2 { |
| 129 | return nil |
| 130 | } |
| 131 | |
| 132 | for _, l := range links { |
| 133 | if l.Name == nil || l.URL == nil { |
| 134 | return fmt.Errorf("%w: missing required fields links.url and links.name", validation.ErrMissingField) |
| 135 | } |
| 136 | |
| 137 | if !linkNameAllowed(*l.Name) { |
| 138 | return fmt.Errorf("invalid value for links.name filed, allowed only: %s", |
| 139 | strings.Join(supportedLinkNames(), ", ")) |
| 140 | } |
| 141 | |
| 142 | prefix := allowedLinkKeys[*l.Name] |
| 143 | if prefix != "" { |
| 144 | if !strings.HasPrefix(*l.URL, prefix) { |
| 145 | return fmt.Errorf("invalid value '%s' for %s link url, allowed only with prefix: %s", |
| 146 | *l.URL, *l.Name, prefix) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if !strings.HasPrefix(*l.URL, "https://") { |
| 151 | return fmt.Errorf("invalid value for links.url field, allowed only with https:// prefix") |
| 152 | } |
| 153 | |
| 154 | if *l.Name == "medium" { |
| 155 | if !strings.Contains(*l.URL, "medium.com") { |
| 156 | return fmt.Errorf("invalid value for links.url field, should contain medium.com") |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return nil |
| 162 | } |
| 163 | |
| 164 | func ValidateCoinType(assetType string) error { |
| 165 | if assetType != "coin" { |
no test coverage detected
searching dependent graphs…