本文整理汇总了Golang中github.com/docker/go-connections/nat.ParsePortSpec函数的典型用法代码示例。如果您正苦于以下问题:Golang ParsePortSpec函数的具体用法?Golang ParsePortSpec怎么用?Golang ParsePortSpec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParsePortSpec函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestExpose
func TestExpose(t *testing.T) {
b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true}
exposedPort := "80"
if err := expose(b, []string{exposedPort}, nil, ""); err != nil {
t.Fatalf("Error should be empty, got: %s", err.Error())
}
if b.runConfig.ExposedPorts == nil {
t.Fatalf("ExposedPorts should be set")
}
if len(b.runConfig.ExposedPorts) != 1 {
t.Fatalf("ExposedPorts should contain only 1 element. Got %s", b.runConfig.ExposedPorts)
}
portsMapping, err := nat.ParsePortSpec(exposedPort)
if err != nil {
t.Fatalf("Error when parsing port spec: %s", err.Error())
}
if _, ok := b.runConfig.ExposedPorts[portsMapping[0].Port]; !ok {
t.Fatalf("Port %s should be present. Got %s", exposedPort, b.runConfig.ExposedPorts)
}
}
示例2: ValidatePort
// ValidatePort validates a string is in the expected format for a port definition
func ValidatePort(value string) (string, error) {
portMappings, err := nat.ParsePortSpec(value)
for _, portMapping := range portMappings {
if portMapping.Binding.HostIP != "" {
return "", fmt.Errorf("HostIP is not supported by a service.")
}
}
return value, err
}