status.go 629 B

12345678910111213141516171819202122232425
  1. // Package googleapi provides helpers for Google-style API responses.
  2. package googleapi
  3. import "net/http"
  4. // HTTPStatusToGoogleStatus maps HTTP status codes to Google-style error status strings.
  5. func HTTPStatusToGoogleStatus(status int) string {
  6. switch status {
  7. case http.StatusBadRequest:
  8. return "INVALID_ARGUMENT"
  9. case http.StatusUnauthorized:
  10. return "UNAUTHENTICATED"
  11. case http.StatusForbidden:
  12. return "PERMISSION_DENIED"
  13. case http.StatusNotFound:
  14. return "NOT_FOUND"
  15. case http.StatusTooManyRequests:
  16. return "RESOURCE_EXHAUSTED"
  17. default:
  18. if status >= 500 {
  19. return "INTERNAL"
  20. }
  21. return "UNKNOWN"
  22. }
  23. }