mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-12 11:14:40 +00:00
ipn: fix formatting of ExitNodeIP in MaskedPrefs
%#v on a netaddr.IP showed the netaddr.IP innards.
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
(cherry picked from commit 751c42c097
)
This commit is contained in:
parent
d76672b5e5
commit
6421ee22f6
19
ipn/prefs.go
19
ipn/prefs.go
@ -234,6 +234,20 @@ func (m *MaskedPrefs) Pretty() string {
|
||||
mt := mv.Type()
|
||||
mpv := reflect.ValueOf(&m.Prefs).Elem()
|
||||
first := true
|
||||
|
||||
format := func(v reflect.Value) string {
|
||||
switch v.Type().Kind() {
|
||||
case reflect.String:
|
||||
return "%s=%q"
|
||||
case reflect.Slice:
|
||||
// []string
|
||||
if v.Type().Elem().Kind() == reflect.String {
|
||||
return "%s=%q"
|
||||
}
|
||||
}
|
||||
return "%s=%v"
|
||||
}
|
||||
|
||||
for i := 1; i < mt.NumField(); i++ {
|
||||
name := mt.Field(i).Name
|
||||
if mv.Field(i).Bool() {
|
||||
@ -241,9 +255,10 @@ func (m *MaskedPrefs) Pretty() string {
|
||||
sb.WriteString(" ")
|
||||
}
|
||||
first = false
|
||||
fmt.Fprintf(&sb, "%s=%#v",
|
||||
f := mpv.Field(i - 1)
|
||||
fmt.Fprintf(&sb, format(f),
|
||||
strings.TrimSuffix(name, "Set"),
|
||||
mpv.Field(i-1).Interface())
|
||||
f.Interface())
|
||||
}
|
||||
}
|
||||
sb.WriteString("}")
|
||||
|
@ -615,12 +615,27 @@ func TestMaskedPrefsPretty(t *testing.T) {
|
||||
OperatorUser: "galaxybrain",
|
||||
AllowSingleHosts: true,
|
||||
RouteAll: false,
|
||||
ExitNodeID: "foo",
|
||||
AdvertiseTags: []string{"tag:foo", "tag:bar"},
|
||||
NetfilterMode: preftype.NetfilterNoDivert,
|
||||
},
|
||||
RouteAllSet: true,
|
||||
HostnameSet: true,
|
||||
OperatorUserSet: true,
|
||||
ExitNodeIDSet: true,
|
||||
AdvertiseTagsSet: true,
|
||||
NetfilterModeSet: true,
|
||||
},
|
||||
want: `MaskedPrefs{RouteAll=false Hostname="bar" OperatorUser="galaxybrain"}`,
|
||||
want: `MaskedPrefs{RouteAll=false ExitNodeID="foo" AdvertiseTags=["tag:foo" "tag:bar"] Hostname="bar" NetfilterMode=nodivert OperatorUser="galaxybrain"}`,
|
||||
},
|
||||
{
|
||||
m: &MaskedPrefs{
|
||||
Prefs: Prefs{
|
||||
ExitNodeIP: netaddr.IPv4(100, 102, 104, 105),
|
||||
},
|
||||
ExitNodeIPSet: true,
|
||||
},
|
||||
want: `MaskedPrefs{ExitNodeIP=100.102.104.105}`,
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user