diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2021-02-19 14:57:58 +0000 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2021-02-19 14:57:58 +0000 |
| commit | d99285e57351176b5e1cdb7a7086c3003a2a5d83 (patch) | |
| tree | 102946175725c8de8a6d1b3466d06adef1849c9c | |
| parent | 5d8da7f0edb5760ed68dd2830089c86ea823ca00 (diff) | |
Use Header.Set to set headers
| -rw-r--r-- | cmd/go-import-redirect/main.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/cmd/go-import-redirect/main.go b/cmd/go-import-redirect/main.go index 6ddfc19..5aedde8 100644 --- a/cmd/go-import-redirect/main.go +++ b/cmd/go-import-redirect/main.go @@ -23,18 +23,18 @@ import ( ) func redirect(resp http.ResponseWriter, req *http.Request) { - if req.Method != "GET" { - resp.Header()["Allow"] = []string{"GET"} + if req.Method != http.MethodGet { + resp.Header().Set("Allow", http.MethodGet) resp.WriteHeader(http.StatusMethodNotAllowed) return } pkg := path.Join(req.Host, req.URL.Path) - resp.Header()["Content-Type"] = []string{"text/html; charset=utf-8"} + resp.Header().Set("Content-Type", "text/html; charset=utf-8") if v, ok := req.URL.Query()["go-get"]; ok && len(v) > 0 && v[0] == "1" { resp.WriteHeader(http.StatusOK) } else { - resp.Header()["Location"] = []string{"https://pkg.go.dev/" + pkg} + resp.Header().Set("Location", "https://pkg.go.dev/"+pkg) resp.WriteHeader(http.StatusFound) } resp.Write([]byte(internal.GetBody(pkg))) |
