mirror of https://github.com/tailscale/tailscale/
util/httpm: add new package for prettier HTTP method constants
See package doc. Change-Id: Ibbfc8e1f98294217c56f3a9452bd93ffa3103572 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>pull/7082/head
parent
2703d6916f
commit
a1b4ab34e6
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2023 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package httpm has shorter names for HTTP method constants.
|
||||
//
|
||||
// Some background: originally Go didn't have http.MethodGet, http.MethodPost
|
||||
// and life was good and people just wrote readable "GET" and "POST". But then
|
||||
// in a moment of weakness Brad and others maintaining net/http caved and let
|
||||
// the http.MethodFoo constants be added and code's been less readable since.
|
||||
// Now the substance of the method name is hidden away at the end after
|
||||
// "http.Method" and they all blend together and it's hard to read code using
|
||||
// them.
|
||||
//
|
||||
// This package is a compromise. It provides constants, but shorter and closer
|
||||
// to how it used to look. It does violate Go style
|
||||
// (https://github.com/golang/go/wiki/CodeReviewComments#mixed-caps) that says
|
||||
// constants shouldn't be SCREAM_CASE. But this isn't INT_MAX; it's GET and
|
||||
// POST, which are already defined as all caps.
|
||||
//
|
||||
// It would be tempting to make these constants be typed but then they wouldn't
|
||||
// be assignable to things in net/http that just want string. Oh well.
|
||||
package httpm
|
||||
|
||||
const (
|
||||
GET = "GET"
|
||||
HEAD = "HEAD"
|
||||
POST = "POST"
|
||||
PUT = "PUT"
|
||||
PATCH = "PATCH"
|
||||
DELETE = "DELETE"
|
||||
CONNECT = "CONNECT"
|
||||
OPTIONS = "OPTIONS"
|
||||
TRACE = "TRACE"
|
||||
SPACEJUMP = "SPACEJUMP" // https://www.w3.org/Protocols/HTTP/Methods/SpaceJump.html
|
||||
)
|
Loading…
Reference in New Issue