mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-22 08:51:41 +00:00
types/empty: add Message, stop using mysterious *struct{}
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
4796f6fd67
commit
747c7d7ce2
@ -21,6 +21,7 @@ import (
|
|||||||
"tailscale.com/logger"
|
"tailscale.com/logger"
|
||||||
"tailscale.com/logtail/backoff"
|
"tailscale.com/logtail/backoff"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
|
"tailscale.com/types/empty"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO(apenwarr): eliminate the 'state' variable, as it's now obsolete.
|
// TODO(apenwarr): eliminate the 'state' variable, as it's now obsolete.
|
||||||
@ -60,7 +61,7 @@ func (s state) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Status struct {
|
type Status struct {
|
||||||
LoginFinished *struct{}
|
LoginFinished *empty.Message
|
||||||
Err string
|
Err string
|
||||||
URL string
|
URL string
|
||||||
Persist *Persist // locally persisted configuration
|
Persist *Persist // locally persisted configuration
|
||||||
@ -507,9 +508,9 @@ func (c *Client) sendStatus(who string, err error, url string, nm *NetworkMap) {
|
|||||||
c.logf("sendStatus: %s: %v\n", who, state)
|
c.logf("sendStatus: %s: %v\n", who, state)
|
||||||
|
|
||||||
var p *Persist
|
var p *Persist
|
||||||
var fin *struct{}
|
var fin *empty.Message
|
||||||
if state == stateAuthenticated {
|
if state == stateAuthenticated {
|
||||||
fin = &struct{}{}
|
fin = new(empty.Message)
|
||||||
}
|
}
|
||||||
if nm != nil && loggedIn && synced {
|
if nm != nil && loggedIn && synced {
|
||||||
pp := c.direct.GetPersist()
|
pp := c.direct.GetPersist()
|
||||||
|
@ -7,6 +7,8 @@ package controlclient
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"tailscale.com/types/empty"
|
||||||
)
|
)
|
||||||
|
|
||||||
func fieldsOf(t reflect.Type) (fields []string) {
|
func fieldsOf(t reflect.Type) (fields []string) {
|
||||||
@ -55,7 +57,7 @@ func TestStatusEqual(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&Status{LoginFinished: nil},
|
&Status{LoginFinished: nil},
|
||||||
&Status{LoginFinished: new(struct{})},
|
&Status{LoginFinished: new(empty.Message)},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"tailscale.com/control/controlclient"
|
"tailscale.com/control/controlclient"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
|
"tailscale.com/types/empty"
|
||||||
"tailscale.com/wgengine"
|
"tailscale.com/wgengine"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ type NetworkMap = controlclient.NetworkMap
|
|||||||
type Notify struct {
|
type Notify struct {
|
||||||
Version string // version number of IPN backend
|
Version string // version number of IPN backend
|
||||||
ErrMessage *string // critical error message, if any
|
ErrMessage *string // critical error message, if any
|
||||||
LoginFinished *struct{} // event: login process succeeded
|
LoginFinished *empty.Message // event: non-nil when login process succeeded
|
||||||
State *State // current IPN state has changed
|
State *State // current IPN state has changed
|
||||||
Prefs *Prefs // preferences were changed
|
Prefs *Prefs // preferences were changed
|
||||||
NetMap *NetworkMap // new netmap received
|
NetMap *NetworkMap // new netmap received
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"tailscale.com/logger"
|
"tailscale.com/logger"
|
||||||
"tailscale.com/portlist"
|
"tailscale.com/portlist"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
|
"tailscale.com/types/empty"
|
||||||
"tailscale.com/version"
|
"tailscale.com/version"
|
||||||
"tailscale.com/wgengine"
|
"tailscale.com/wgengine"
|
||||||
"tailscale.com/wgengine/filter"
|
"tailscale.com/wgengine/filter"
|
||||||
@ -194,8 +195,7 @@ func (b *LocalBackend) Start(opts Options) error {
|
|||||||
// Auth completed, unblock the engine
|
// Auth completed, unblock the engine
|
||||||
b.blockEngineUpdates(false)
|
b.blockEngineUpdates(false)
|
||||||
b.authReconfig()
|
b.authReconfig()
|
||||||
noargs := struct{}{}
|
b.send(Notify{LoginFinished: &empty.Message{}})
|
||||||
b.send(Notify{LoginFinished: &noargs})
|
|
||||||
}
|
}
|
||||||
if new.Persist != nil {
|
if new.Persist != nil {
|
||||||
persist := *new.Persist // copy
|
persist := *new.Persist // copy
|
||||||
|
14
types/empty/message.go
Normal file
14
types/empty/message.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Package empty defines an empty struct type.
|
||||||
|
package empty
|
||||||
|
|
||||||
|
// Message is an empty message. Its purpose is to be used as pointer
|
||||||
|
// type where nil and non-nil distinguish whether it's set. This is
|
||||||
|
// used instead of a bool when we want to marshal it as a JSON empty
|
||||||
|
// object (or null) for the future ability to add other fields, at
|
||||||
|
// which point callers would define a new struct and not use
|
||||||
|
// empty.Message.
|
||||||
|
type Message struct{}
|
Loading…
x
Reference in New Issue
Block a user