mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-13 22:47:30 +00:00
util/mak: move tailssh's mapSet into a new package for reuse elsewhere
Change-Id: Idfe95db82275fd2be6ca88f245830731a0d5aecf Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
c2eff20008
commit
910ae68e0b
@@ -40,6 +40,7 @@ import (
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/tempfork/gliderlabs/ssh"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/util/mak"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -471,7 +472,7 @@ func (srv *server) fetchPublicKeysURL(url string) ([]string, error) {
|
||||
|
||||
srv.mu.Lock()
|
||||
defer srv.mu.Unlock()
|
||||
mapSet(&srv.fetchPublicKeysCache, url, pubKeyCacheEntry{
|
||||
mak.Set(&srv.fetchPublicKeysCache, url, pubKeyCacheEntry{
|
||||
at: srv.now(),
|
||||
lines: lines,
|
||||
etag: etag,
|
||||
@@ -731,8 +732,8 @@ func (srv *server) startSession(ss *sshSession) {
|
||||
if _, dup := srv.activeSessionBySharedID[ss.sharedID]; dup {
|
||||
panic("dup sharedID")
|
||||
}
|
||||
mapSet(&srv.activeSessionByH, ss.idH, ss)
|
||||
mapSet(&srv.activeSessionBySharedID, ss.sharedID, ss)
|
||||
mak.Set(&srv.activeSessionByH, ss.idH, ss)
|
||||
mak.Set(&srv.activeSessionBySharedID, ss.sharedID, ss)
|
||||
}
|
||||
|
||||
// endSession unregisters s from the list of active sessions.
|
||||
@@ -1248,11 +1249,3 @@ func envEq(a, b string) bool {
|
||||
}
|
||||
return a == b
|
||||
}
|
||||
|
||||
// mapSet assigns m[k] = v, making m if necessary.
|
||||
func mapSet[K comparable, V any](m *map[K]V, k K, v V) {
|
||||
if *m == nil {
|
||||
*m = make(map[K]V)
|
||||
}
|
||||
(*m)[k] = v
|
||||
}
|
||||
|
Reference in New Issue
Block a user