github.com/mtsmfm/go/src@v0.0.0-20221020090648-44bdcb9f8fde/internal/godebug/godebug.go (about) 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 _ "unsafe" // go:linkname 9 10 //go:linkname getGODEBUG 11 func getGODEBUG() string 12 13 // Get returns the value for the provided GODEBUG key. 14 func Get(key string) string { 15 return get(getGODEBUG(), key) 16 } 17 18 // get returns the value part of key=value in s (a GODEBUG value). 19 func get(s, key string) string { 20 for i := 0; i < len(s)-len(key)-1; i++ { 21 if i > 0 && s[i-1] != ',' { 22 continue 23 } 24 afterKey := s[i+len(key):] 25 if afterKey[0] != '=' || s[i:i+len(key)] != key { 26 continue 27 } 28 val := afterKey[1:] 29 for i, b := range val { 30 if b == ',' { 31 return val[:i] 32 } 33 } 34 return val 35 } 36 return "" 37 }