| 1 |
// Copyright 2021 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
// Package godebug parses the GODEBUG environment variable. |
| 6 |
package godebug |
| 7 |
|
| 8 |
import "os" |
| 9 |
|
| 10 |
// Get returns the value for the provided GODEBUG key. |
| 11 |
func Get(key string) string { |
| 12 |
return get(os.Getenv("GODEBUG"), key) |
| 13 |
} |
| 14 |
|
| 15 |
// get returns the value part of key=value in s (a GODEBUG value). |
| 16 |
func get(s, key string) string { |
| 17 |
for i := 0; i < len(s)-len(key)-1; i++ { |
| 18 |
if i > 0 && s[i-1] != ',' { |
| 19 |
continue |
| 20 |
} |
| 21 |
afterKey := s[i+len(key):] |
| 22 |
if afterKey[0] != '=' || s[i:i+len(key)] != key { |
| 23 |
continue |
| 24 |
} |
| 25 |
val := afterKey[1:] |
| 26 |
for i, b := range val { |
| 27 |
if b == ',' { |
| 28 |
return val[:i] |
| 29 |
} |
| 30 |
} |
| 31 |
return val |
| 32 |
} |
| 33 |
return "" |
| 34 |
} |