{"record":{"id":"47839968fe956aac","repo":"flipped-aurora/gin-vue-admin","slug":"s-478399","errorCode":null,"errorMessage":"不支持的目标系统: %s","messagePattern":"不支持的目标系统: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/plugin/ai/service/sys_cli_build.go","lineNumber":41,"sourceCode":")\n\nvar (\n\tcliBuildGOOSAllowList   = map[string]struct{}{\"windows\": {}, \"linux\": {}, \"darwin\": {}}\n\tcliBuildGOARCHAllowList = map[string]struct{}{\"amd64\": {}, \"arm64\": {}}\n)\n\n// normalizeBuildTarget 校验并归一化目标平台。空值回退到当前运行平台。\nfunc normalizeBuildTarget(goos, goarch string) (string, string, error) {\n\tgoos = strings.ToLower(strings.TrimSpace(goos))\n\tgoarch = strings.ToLower(strings.TrimSpace(goarch))\n\tif goos == \"\" {\n\t\tgoos = runtime.GOOS\n\t}\n\tif goarch == \"\" {\n\t\tgoarch = runtime.GOARCH\n\t}\n\tif _, ok := cliBuildGOOSAllowList[goos]; !ok {\n\t\treturn \"\", \"\", fmt.Errorf(\"不支持的目标系统: %s\", goos)\n\t}\n\tif _, ok := cliBuildGOARCHAllowList[goarch]; !ok {\n\t\treturn \"\", \"\", fmt.Errorf(\"不支持的目标架构: %s\", goarch)\n\t}\n\treturn goos, goarch, nil\n}\n\n// cliBinaryExt 返回目标平台对应的二进制后缀。\nfunc cliBinaryExt(goos string) string {\n\tif goos == \"windows\" {\n\t\treturn \".exe\"\n\t}\n\treturn \"\"\n}\n\n// BuildCliBinary 把指定 CLI 的 manifest 内嵌进 gva 源码副本，交叉编译出一个开箱即用的二进制。\nfunc (s *cliService) BuildCliBinary(ctx context.Context, req autoReq.BuildSysCliBinaryRequest) (string, []byte, error) {\n\tgoos, goarch, err := normalizeBuildTarget(req.GOOS, req.GOARCH)","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/plugin/ai/service/sys_cli_build.go#L23-L59","documentation":"normalizeBuildTarget validates a requested cross-compile target OS against cliBuildGOOSAllowList. If the caller passes a goos value (or the server runtime.GOOS fallback) that is not in the allow list, the build is rejected early instead of letting `go build` fail with a confusing GOOS error. This is an intentional whitelist guard for the CLI binary compile feature.","triggerScenarios":"Calling BuildCliBinary or BuildCliSkill with an explicit goos value outside the allow list (e.g. \"freebsd\", \"windows95\", typo like \"darwin2\"), or running the server on a GOOS not in the allow list and relying on the runtime.GOOS default.","commonSituations":"Typoed target OS in build params; attempting to build for an exotic/embedded platform; a server deployed on an unusual OS whose runtime.GOOS isn't whitelisted; API callers passing raw user input for target OS without pre-validation.","solutions":["Check the requested goos against the allowlist values (typically linux/darwin/windows) and pick a supported one","Fix typos in the goos parameter (e.g. \"linux\" not \"Linux\" or \"linus\")","If the platform genuinely must be supported, add it to cliBuildGOOSAllowList and verify CGO_ENABLED=0 cross-compilation works","Validate user-supplied target OS at the API/frontend layer before invoking the build service"],"exampleFix":"// before\nsvc.BuildCliBinary(cli, manifest, \"freebsd\", \"amd64\")\n// after\nsvc.BuildCliBinary(cli, manifest, \"linux\", \"amd64\") // goos must be in cliBuildGOOSAllowList","handlingStrategy":"validation","validationCode":"var cliBuildGOOSAllowList = map[string]bool{\"linux\": true, \"darwin\": true, \"windows\": true}\nif !cliBuildGOOSAllowList[goos] {\n    return fmt.Errorf(\"unsupported GOOS %q; allowed: linux, darwin, windows\", goos)\n}","typeGuard":"func isSupportedGOOS(goos string) bool {\n    return map[string]bool{\"linux\": true, \"darwin\": true, \"windows\": true}[goos]\n}","tryCatchPattern":"goos, goarch, err := normalizeBuildTarget(inGoos, inGoarch)\nif err != nil {\n    return nil, fmt.Errorf(\"invalid build target: %w\", err)\n}","preventionTips":["Expose the allowlist via an API/dropdown so users can only pick supported GOOS values","Never pass raw user input as GOOS without checking against the allowlist","Use Go's canonical GOOS names, lowercase"],"tags":["go","cross-compile","validation","whitelist"],"backgroundTag":"unsupported-build-target","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}