yao/agent/context/utils.go
Max 8dca4719c0 Remove deprecated agent API files and refactor agent loading logic
- Deleted obsolete agent API files (agent.go, api.go, api_test.go, types.go) to streamline the codebase.
- Refactored the agent loading logic to initialize the API instance correctly, ensuring proper integration with the new structure.
- Updated context handling to improve clarity and maintainability across the agent's functionality.
- Enhanced error handling and cache management in the agent's initialization process.
2025-11-11 11:23:20 +08:00

53 lines
1.4 KiB
Go

package context
// getValidatedValue gets value from query, header, or default, and validates it
func getValidatedValue(queryValue, headerValue, defaultValue string, validator func(string) string) string {
if queryValue != "" {
return validator(queryValue)
}
if headerValue != "" {
return validator(headerValue)
}
return defaultValue
}
// getValidatedAccept gets Accept from query, header, or parse from client type
func getValidatedAccept(queryValue, headerValue, clientType string) Accept {
if queryValue != "" {
return validateAccept(queryValue)
}
if headerValue != "" {
return validateAccept(headerValue)
}
return parseAccept(clientType)
}
// validateReferer validates and returns a valid Referer, returns RefererAPI if invalid
func validateReferer(referer string) string {
if ValidReferers[referer] {
return referer
}
return RefererAPI
}
// validateAccept validates and returns a valid Accept type, returns AcceptStandard if invalid
func validateAccept(accept string) Accept {
if ValidAccepts[accept] {
return Accept(accept)
}
return AcceptStandard
}
// parseAccept determines the accept type based on client type
func parseAccept(clientType string) Accept {
switch clientType {
case "web":
return AcceptWebCUI
case "android", "ios":
return AccepNativeCUI
case "windows", "macos", "linux":
return AcceptDesktopCUI
default:
return AcceptStandard
}
}