mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-01 17:49:02 +00:00
all: use cmpx.Or where it made sense
I left a few out where writing it explicitly was better for various reasons. Updates #8296 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
699996ad6c
commit
eefee6f149
@@ -27,6 +27,7 @@ import (
|
||||
"tailscale.com/net/tsaddr"
|
||||
"tailscale.com/tsweb/varz"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/util/cmpx"
|
||||
"tailscale.com/util/vizerror"
|
||||
)
|
||||
|
||||
@@ -144,10 +145,7 @@ func (h Port80Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// Redirect authorized user to the debug handler.
|
||||
path = "/debug/"
|
||||
}
|
||||
host := h.FQDN
|
||||
if host == "" {
|
||||
host = r.Host
|
||||
}
|
||||
host := cmpx.Or(h.FQDN, r.Host)
|
||||
target := "https://" + host + path
|
||||
http.Redirect(w, r, target, http.StatusFound)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tailscale.com/metrics"
|
||||
"tailscale.com/util/cmpx"
|
||||
"tailscale.com/version"
|
||||
)
|
||||
|
||||
@@ -96,16 +97,10 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
|
||||
|
||||
switch v := kv.Value.(type) {
|
||||
case *expvar.Int:
|
||||
if typ == "" {
|
||||
typ = "counter"
|
||||
}
|
||||
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, typ, name, v.Value())
|
||||
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmpx.Or(typ, "counter"), name, v.Value())
|
||||
return
|
||||
case *expvar.Float:
|
||||
if typ == "" {
|
||||
typ = "gauge"
|
||||
}
|
||||
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, typ, name, v.Value())
|
||||
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmpx.Or(typ, "gauge"), name, v.Value())
|
||||
return
|
||||
case *metrics.Set:
|
||||
v.Do(func(kv expvar.KeyValue) {
|
||||
|
||||
Reference in New Issue
Block a user