mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-09 08:01:31 +00:00
all: use any instead of interface{}
My favorite part of generics. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:

committed by
Josh Bleecher Snyder

parent
5f176f24db
commit
0868329936
@@ -189,7 +189,7 @@ func (ap *AuthPath) CompleteSuccessfully() {
|
||||
ap.closeOnce.Do(ap.completeSuccessfully)
|
||||
}
|
||||
|
||||
func (s *Server) logf(format string, a ...interface{}) {
|
||||
func (s *Server) logf(format string, a ...any) {
|
||||
if s.Logf != nil {
|
||||
s.Logf(format, a...)
|
||||
} else {
|
||||
@@ -779,7 +779,7 @@ func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse,
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *Server) sendMapMsg(w http.ResponseWriter, mkey key.MachinePublic, compress bool, msg interface{}) error {
|
||||
func (s *Server) sendMapMsg(w http.ResponseWriter, mkey key.MachinePublic, compress bool, msg any) error {
|
||||
resBytes, err := s.encode(mkey, compress, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -803,7 +803,7 @@ func (s *Server) sendMapMsg(w http.ResponseWriter, mkey key.MachinePublic, compr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) decode(mkey key.MachinePublic, msg []byte, v interface{}) error {
|
||||
func (s *Server) decode(mkey key.MachinePublic, msg []byte, v any) error {
|
||||
if len(msg) == msgLimit {
|
||||
return errors.New("encrypted message too long")
|
||||
}
|
||||
@@ -816,7 +816,7 @@ func (s *Server) decode(mkey key.MachinePublic, msg []byte, v interface{}) error
|
||||
}
|
||||
|
||||
var zstdEncoderPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
New: func() any {
|
||||
encoder, err := smallzstd.NewEncoder(nil, zstd.WithEncoderLevel(zstd.SpeedFastest))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -825,7 +825,7 @@ var zstdEncoderPool = &sync.Pool{
|
||||
},
|
||||
}
|
||||
|
||||
func (s *Server) encode(mkey key.MachinePublic, compress bool, v interface{}) (b []byte, err error) {
|
||||
func (s *Server) encode(mkey key.MachinePublic, compress bool, v any) (b []byte, err error) {
|
||||
var isBytes bool
|
||||
if b, isBytes = v.([]byte); !isBytes {
|
||||
b, err = json.Marshal(v)
|
||||
|
@@ -82,7 +82,7 @@ type LogLineTracker struct {
|
||||
}
|
||||
|
||||
// Logf logs to its underlying logger and also tracks that the given format pattern has been seen.
|
||||
func (lt *LogLineTracker) Logf(format string, args ...interface{}) {
|
||||
func (lt *LogLineTracker) Logf(format string, args ...any) {
|
||||
lt.mu.Lock()
|
||||
if lt.closed {
|
||||
lt.mu.Unlock()
|
||||
@@ -131,7 +131,7 @@ type MemLogger struct {
|
||||
bytes.Buffer
|
||||
}
|
||||
|
||||
func (ml *MemLogger) Logf(format string, args ...interface{}) {
|
||||
func (ml *MemLogger) Logf(format string, args ...any) {
|
||||
ml.Lock()
|
||||
defer ml.Unlock()
|
||||
fmt.Fprintf(&ml.Buffer, format, args...)
|
||||
|
@@ -66,16 +66,16 @@ func (p *Packet) short() string {
|
||||
return fmt.Sprintf("%s/%s", payload, tuple)
|
||||
}
|
||||
|
||||
func (p *Packet) Trace(msg string, args ...interface{}) {
|
||||
func (p *Packet) Trace(msg string, args ...any) {
|
||||
if !traceOn {
|
||||
return
|
||||
}
|
||||
allArgs := []interface{}{p.short(), p.locator, p.Src, p.Dst}
|
||||
allArgs := []any{p.short(), p.locator, p.Src, p.Dst}
|
||||
allArgs = append(allArgs, args...)
|
||||
fmt.Fprintf(os.Stderr, "[%s]%s src=%s dst=%s "+msg+"\n", allArgs...)
|
||||
}
|
||||
|
||||
func (p *Packet) setLocator(msg string, args ...interface{}) {
|
||||
func (p *Packet) setLocator(msg string, args ...any) {
|
||||
p.locator = fmt.Sprintf(" "+msg, args...)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user