generictypes

package module
v0.0.0-...-e7042c3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2015 License: Apache-2.0 Imports: 10 Imported by: 2

README

generic-types-go

This repository is intended to house generally usable types that are missing from the standard library (Domains) or a bit more specific for the containerized world we live in (DockerImage, DockerPort). All types should support JSON serialization and a validation logic. Errors are wrapped with github.com/juju/errgo.

Documentation

Index

Constants

View Source
const (
	ProtocolTCP = "tcp"
	ProtocolUDP = "udp"
)

Variables

View Source
var (
	// https://github.com/docker/docker/blob/6d6dc2c1a1e36a2c3992186664d4513ce28e84ae/registry/registry.go#L27
	PatternNamespace = regexp.MustCompile(`^([a-z0-9_]{4,30})$`)
	PatternImage     = regexp.MustCompile(`^([a-z0-9-_.]+)$`)
	PatternVersion   = regexp.MustCompile("^[a-zA-Z0-9-\\._]+$")
)
View Source
var (
	// NOTE: This format description is slightly different from what we parse down there.
	// The format given here is the one docker documents. But the repository also consist of a
	// namespace which is more or less always there. Since our business logic requires some checks based on the
	// namespace, we parse it explicitly.
	ErrInvalidFormat = errgo.New("Not a valid docker image. Format: [<registry>/]<repository>[:<version>]")
)

Functions

This section is empty.

Types

type DockerImage

type DockerImage struct {
	Registry   string // The registry name
	Namespace  string // The namespace
	Repository string // The repository name
	Version    string // The version part
}

func MustParseDockerImage

func MustParseDockerImage(image string) DockerImage

func ParseDockerImage

func ParseDockerImage(image string) (DockerImage, error)

func (DockerImage) DefaultLatestVersion

func (img DockerImage) DefaultLatestVersion() DockerImage

DefaultLatestVersion returns an image that has Version set to "latest" when it is unspecified.

func (DockerImage) DefaultLibraryNamespace

func (img DockerImage) DefaultLibraryNamespace() DockerImage

DefaultLibraryNamespace returns an image that has Namespace set to "library" when it is unspecified.

func (DockerImage) MarshalJSON

func (img DockerImage) MarshalJSON() ([]byte, error)

func (DockerImage) String

func (img DockerImage) String() string

Returns all image information combined: <registry>/<namespace>/<repository>:<version>

func (*DockerImage) UnmarshalJSON

func (img *DockerImage) UnmarshalJSON(data []byte) error

func (DockerImage) UnversionedString

func (img DockerImage) UnversionedString() string

Returns all image information except for the version: <registry>/<namespace>/<repository>

func (DockerImage) Validate

func (img DockerImage) Validate() error

Validate checks that the given docker image is valid. Returns nil if valid, or an error if not valid.

type DockerPort

type DockerPort struct {
	// The port number.
	Port string

	// The protocol to use. "tcp" or "udp"
	Protocol string
	// contains filtered or unexported fields
}

func MustParseDockerPort

func MustParseDockerPort(port string) DockerPort

func ParseDockerPort

func ParseDockerPort(port string) (DockerPort, error)

func (*DockerPort) Empty

func (d *DockerPort) Empty() bool

Empty returns true if this port is equal to "", false otherwise.

func (*DockerPort) Equals

func (d *DockerPort) Equals(other DockerPort) bool

func (DockerPort) MarshalJSON

func (d DockerPort) MarshalJSON() ([]byte, error)

func (DockerPort) String

func (d DockerPort) String() string

func (*DockerPort) UnmarshalJSON

func (d *DockerPort) UnmarshalJSON(data []byte) error

type Domain

type Domain string

func (*Domain) MarshalJSON

func (d *Domain) MarshalJSON() ([]byte, error)

func (*Domain) String

func (d *Domain) String() string

func (*Domain) UnmarshalJSON

func (d *Domain) UnmarshalJSON(data []byte) error

func (*Domain) Validate

func (d *Domain) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL