| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
package mcpgodebug |
| 13 |
|
| 14 |
import ( |
| 15 |
"fmt" |
| 16 |
"os" |
| 17 |
"strings" |
| 18 |
) |
| 19 |
|
| 20 |
const compatibilityEnvKey = "MCPGODEBUG" |
| 21 |
|
| 22 |
var compatibilityParams map[string]string |
| 23 |
|
| 24 |
func init() { |
| 25 |
var err error |
| 26 |
compatibilityParams, err = parseCompatibility(os.Getenv(compatibilityEnvKey)) |
| 27 |
if err != nil { |
| 28 |
panic(err) |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
func Value(key string) string { |
| 35 |
return compatibilityParams[key] |
| 36 |
} |
| 37 |
|
| 38 |
func parseCompatibility(envValue string) (map[string]string, error) { |
| 39 |
if envValue == "" { |
| 40 |
return nil, nil |
| 41 |
} |
| 42 |
|
| 43 |
params := make(map[string]string) |
| 44 |
for part := range strings.SplitSeq(envValue, ",") { |
| 45 |
k, v, ok := strings.Cut(part, "=") |
| 46 |
if !ok { |
| 47 |
return nil, fmt.Errorf("MCPGODEBUG: invalid format: %q", part) |
| 48 |
} |
| 49 |
params[strings.TrimSpace(k)] = strings.TrimSpace(v) |
| 50 |
} |
| 51 |
return params, nil |
| 52 |
} |