/
docker_container_registry.go
49 lines (40 loc) · 1.19 KB
/
docker_container_registry.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 feeds
import (
"fmt"
"github.com/go-playground/validator/v10"
"github.com/go-playground/validator/v10/non-standard/validators"
)
// DockerContainerRegistry represents a Docker container registry.
type DockerContainerRegistry struct {
APIVersion string `json:"ApiVersion,omitempty"`
FeedURI string `json:"FeedUri,omitempty"`
RegistryPath string `json:"RegistryPath,omitempty"`
feed
}
// NewDockerContainerRegistry creates and initializes a Docker container
// registry.
func NewDockerContainerRegistry(name string) (*DockerContainerRegistry, error) {
if len(name) == 0 {
return nil, fmt.Errorf("the required parameter, name is nil or empty")
}
feed := DockerContainerRegistry{
FeedURI: "https://index.docker.io",
feed: *newFeed(name, FeedTypeDocker),
}
// validate to ensure that all expectations are met
err := feed.Validate()
if err != nil {
return nil, err
}
return &feed, nil
}
// Validate checks the state of this Docker container registry and returns an
// error if invalid.
func (d *DockerContainerRegistry) Validate() error {
v := validator.New()
err := v.RegisterValidation("notblank", validators.NotBlank)
if err != nil {
return err
}
return v.Struct(d)
}