2021-08-02 14:55:51 -07:00
|
|
|
// Copyright 2021 The Go 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 godebug parses the GODEBUG environment variable.
|
|
|
|
|
package godebug
|
|
|
|
|
|
2022-10-17 15:34:50 -04:00
|
|
|
import _ "unsafe" // go:linkname
|
|
|
|
|
|
|
|
|
|
//go:linkname getGODEBUG
|
|
|
|
|
func getGODEBUG() string
|
2021-08-02 14:55:51 -07:00
|
|
|
|
|
|
|
|
// Get returns the value for the provided GODEBUG key.
|
|
|
|
|
func Get(key string) string {
|
2022-10-17 15:34:50 -04:00
|
|
|
return get(getGODEBUG(), key)
|
2021-08-02 14:55:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get returns the value part of key=value in s (a GODEBUG value).
|
|
|
|
|
func get(s, key string) string {
|
|
|
|
|
for i := 0; i < len(s)-len(key)-1; i++ {
|
|
|
|
|
if i > 0 && s[i-1] != ',' {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
afterKey := s[i+len(key):]
|
|
|
|
|
if afterKey[0] != '=' || s[i:i+len(key)] != key {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
val := afterKey[1:]
|
|
|
|
|
for i, b := range val {
|
|
|
|
|
if b == ',' {
|
|
|
|
|
return val[:i]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return val
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|