httpm.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Package httpm has shorter names for HTTP method constants.
  4. //
  5. // Some background: originally Go didn't have http.MethodGet, http.MethodPost
  6. // and life was good and people just wrote readable "GET" and "POST". But then
  7. // in a moment of weakness Brad and others maintaining net/http caved and let
  8. // the http.MethodFoo constants be added and code's been less readable since.
  9. // Now the substance of the method name is hidden away at the end after
  10. // "http.Method" and they all blend together and it's hard to read code using
  11. // them.
  12. //
  13. // This package is a compromise. It provides constants, but shorter and closer
  14. // to how it used to look. It does violate Go style
  15. // (https://github.com/golang/go/wiki/CodeReviewComments#mixed-caps) that says
  16. // constants shouldn't be SCREAM_CASE. But this isn't INT_MAX; it's GET and
  17. // POST, which are already defined as all caps.
  18. //
  19. // It would be tempting to make these constants be typed but then they wouldn't
  20. // be assignable to things in net/http that just want string. Oh well.
  21. package httpm
  22. const (
  23. GET = "GET"
  24. HEAD = "HEAD"
  25. POST = "POST"
  26. PUT = "PUT"
  27. PATCH = "PATCH"
  28. DELETE = "DELETE"
  29. CONNECT = "CONNECT"
  30. OPTIONS = "OPTIONS"
  31. TRACE = "TRACE"
  32. SPACEJUMP = "SPACEJUMP" // https://www.w3.org/Protocols/HTTP/Methods/SpaceJump.html
  33. BREW = "BREW" // https://datatracker.ietf.org/doc/html/rfc2324#section-2.1.1
  34. )