File: types.go

package info (click to toggle)
golang-github-coreos-pkg 3-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 320 kB
  • sloc: sh: 30; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 853 bytes parent folder | download | duplicates (5)
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
package flagutil

import (
	"errors"
	"fmt"
	"net"
	"strings"
)

// IPv4Flag parses a string into a net.IP after asserting that it
// is an IPv4 address. This type implements the flag.Value interface.
type IPv4Flag struct {
	val net.IP
}

func (f *IPv4Flag) IP() net.IP {
	return f.val
}

func (f *IPv4Flag) Set(v string) error {
	ip := net.ParseIP(v)
	if ip == nil || ip.To4() == nil {
		return errors.New("not an IPv4 address")
	}
	f.val = ip
	return nil
}

func (f *IPv4Flag) String() string {
	return f.val.String()
}

// StringSliceFlag parses a comma-delimited list of strings into
// a []string. This type implements the flag.Value interface.
type StringSliceFlag []string

func (ss *StringSliceFlag) String() string {
	return fmt.Sprintf("%+v", *ss)
}

func (ss *StringSliceFlag) Set(v string) error {
	*ss = strings.Split(v, ",")
	return nil
}