本文整理匯總了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
}