package auth import ( "encoding/json" "net/http" "time" "git.x2erp.com/qdy/go-base/logger" ) // 未授权响应 func unauthorized(w http.ResponseWriter, message string) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusUnauthorized) // 简单JSON响应 response := map[string]interface{}{ "success": false, "error": message, "time": time.Now().Format(time.RFC3339), } json.NewEncoder(w).Encode(response) // 记录日志 logger.Warn("Basic认证失败: %s", message) }