tailscale/tailscale
Vedi su GitHubmake go helper for "parsed string or fallback value" pattern
Open
#20.018 aperta il 5 giu 2026
good first issue
Metriche repository
- Star
- (31.565 star)
- Metriche merge PR
- (Merge medio 5g 22h) (173 PR mergiate in 30 g)
Descrizione
We have this pattern of "parse string S as type T, but return a fallback value V if parsing fails" all over the place for common T types like bool, time.Duration, etc. In case a util helper doesn't exist already, we should make one and make it discoverable.
func defDuration(a string, def time.Duration) time.Duration {
if a == "" {
return def
}
v, err := time.ParseDuration(a)
if err != nil {
return def
}
return v
}
Some examples in 5 mins of searching:
- https://github.com/tailscale/tailscale/blob/3ec5be3f510f74738179c1023468343a62a7e00f/feature/debugportmapper/debugportmapper.go#L195
- https://github.com/tailscale/tailscale/blob/2ee9eacb9437a2fb631f109621cfe0d0181042cd/feature/routecheck/localapi.go#L65
- https://github.com/tailscale/tailscale/blob/85d6ba9473cdeb62329ad71940290cad7ef9dc6e/cmd/k8s-operator/sts.go#L1268
- https://github.com/tailscale/tailscale/blob/5ef3713c9fb0896fee566918d9f5f932c66086d9/cmd/containerboot/settings.go#L499
- https://github.com/tailscale/tailscale/blob/d961e4485609b521d29529bc0519108ba60f2854/cmd/testwrapper/testwrapper.go#L76