summaryrefslogtreecommitdiffhomepage
path: root/types/flagtype
diff options
context:
space:
mode:
Diffstat (limited to 'types/flagtype')
-rw-r--r--types/flagtype/flagtype.go90
1 files changed, 45 insertions, 45 deletions
diff --git a/types/flagtype/flagtype.go b/types/flagtype/flagtype.go
index be160dee8..c76b16353 100644
--- a/types/flagtype/flagtype.go
+++ b/types/flagtype/flagtype.go
@@ -1,45 +1,45 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-// Package flagtype defines flag.Value types.
-package flagtype
-
-import (
- "errors"
- "flag"
- "fmt"
- "math"
- "strconv"
- "strings"
-)
-
-type portValue struct{ n *uint16 }
-
-func PortValue(dst *uint16, defaultPort uint16) flag.Value {
- *dst = defaultPort
- return portValue{dst}
-}
-
-func (p portValue) String() string {
- if p.n == nil {
- return ""
- }
- return fmt.Sprint(*p.n)
-}
-func (p portValue) Set(v string) error {
- if v == "" {
- return errors.New("can't be the empty string")
- }
- if strings.Contains(v, ":") {
- return errors.New("expecting just a port number, without a colon")
- }
- n, err := strconv.ParseUint(v, 10, 64) // use 64 instead of 16 to return nicer error message
- if err != nil {
- return fmt.Errorf("not a valid number")
- }
- if n > math.MaxUint16 {
- return errors.New("out of range for port number")
- }
- *p.n = uint16(n)
- return nil
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+// Package flagtype defines flag.Value types.
+package flagtype
+
+import (
+ "errors"
+ "flag"
+ "fmt"
+ "math"
+ "strconv"
+ "strings"
+)
+
+type portValue struct{ n *uint16 }
+
+func PortValue(dst *uint16, defaultPort uint16) flag.Value {
+ *dst = defaultPort
+ return portValue{dst}
+}
+
+func (p portValue) String() string {
+ if p.n == nil {
+ return ""
+ }
+ return fmt.Sprint(*p.n)
+}
+func (p portValue) Set(v string) error {
+ if v == "" {
+ return errors.New("can't be the empty string")
+ }
+ if strings.Contains(v, ":") {
+ return errors.New("expecting just a port number, without a colon")
+ }
+ n, err := strconv.ParseUint(v, 10, 64) // use 64 instead of 16 to return nicer error message
+ if err != nil {
+ return fmt.Errorf("not a valid number")
+ }
+ if n > math.MaxUint16 {
+ return errors.New("out of range for port number")
+ }
+ *p.n = uint16(n)
+ return nil
+}