fix(t233): add redacted ERP diagnostics

This commit is contained in:
QiuSW
2026-07-29 11:24:04 +08:00
parent 817a968233
commit 1e703ef257
14 changed files with 412 additions and 28 deletions
+26
View File
@@ -23,6 +23,7 @@ const (
ShunyunbaoUsernameEnvironment = "CMROUBAO_SHUNYUNBAO_USERNAME"
ShunyunbaoPasswordEnvironment = "CMROUBAO_SHUNYUNBAO_PASSWORD"
OCRAPIURLEnvironment = "CMROUBAO_OCR_API_URL"
ERPDebugLogEnvironment = "CMROUBAO_ERP_DEBUG_LOG"
defaultHTTPAddress = "127.0.0.1:8080"
defaultDatabasePath = "var/cmroubao.db"
@@ -55,6 +56,7 @@ type Config struct {
ShunyunbaoPassword string
OCRAPIURL string
ShunyunbaoTimeout time.Duration
ERPDebugLog bool
}
func Load(lookup LookupEnvironment) (Config, error) {
@@ -186,6 +188,10 @@ func Load(lookup LookupEnvironment) (Config, error) {
if ocrAPISet && !validOCRAPIURL(ocrAPIURL) {
return Config{}, errors.New(OCRAPIURLEnvironment + " must be an approved OCR endpoint")
}
erpDebugLog, err := booleanEnvironment(lookup, ERPDebugLogEnvironment, false)
if err != nil {
return Config{}, err
}
return Config{
HTTPAddress: httpAddress,
@@ -207,6 +213,7 @@ func Load(lookup LookupEnvironment) (Config, error) {
ShunyunbaoPassword: shunyunbaoPassword,
OCRAPIURL: ocrAPIURL,
ShunyunbaoTimeout: 30 * time.Second,
ERPDebugLog: erpDebugLog,
}, nil
}
@@ -267,6 +274,25 @@ func durationEnvironment(
return duration, nil
}
func booleanEnvironment(
lookup LookupEnvironment,
name string,
defaultValue bool,
) (bool, error) {
value, exists := lookup(name)
if !exists {
return defaultValue, nil
}
switch strings.ToLower(strings.TrimSpace(value)) {
case "true":
return true, nil
case "false":
return false, nil
default:
return false, errors.New(name + " must be true or false")
}
}
func cleanOptionalPath(value string) string {
if value == "" {
return ""