-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ContentTypeForm functionality to DecodeForm #4
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
580863c
switching to ajg/form and adding http status constants
syntaqx b6a7960
Merge branch 'master' of github.com:go-chi/render
syntaqx 17b67c4
fixing merge conflicts, actually.
syntaqx 9fd658c
really fixing merge conflicts
syntaqx a54e4ac
removing vendor folder
syntaqx bf4aca9
ignoring vendor folder from vcs
syntaqx af1759a
removing boilerplate toml
syntaqx 99dff9a
modernizing DecodeForm changeset
syntaqx 126d5e7
Merge branch 'master' of github.com:go-chi/render
syntaqx 6a082d9
swapping travis for github actions
syntaqx 56c7eb9
removing minor.patch specificity of actions/cache
syntaqx d098851
adding nolint errcheck until a config can be added
syntaqx File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: test | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- run: go mod download | ||
- name: Run tests | ||
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/go-chi/render | ||
|
||
go 1.16 | ||
|
||
require github.com/ajg/form v1.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= | ||
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ func PlainText(w http.ResponseWriter, r *http.Request, v string) { | |
if status, ok := r.Context().Value(StatusCtxKey).(int); ok { | ||
w.WriteHeader(status) | ||
} | ||
w.Write([]byte(v)) | ||
w.Write([]byte(v)) //nolint:errcheck | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
} | ||
|
||
// Data writes raw bytes to the response, setting the Content-Type as | ||
|
@@ -76,7 +76,7 @@ func Data(w http.ResponseWriter, r *http.Request, v []byte) { | |
if status, ok := r.Context().Value(StatusCtxKey).(int); ok { | ||
w.WriteHeader(status) | ||
} | ||
w.Write(v) | ||
w.Write(v) //nolint:errcheck | ||
} | ||
|
||
// HTML writes a string to the response, setting the Content-Type as text/html. | ||
|
@@ -85,7 +85,7 @@ func HTML(w http.ResponseWriter, r *http.Request, v string) { | |
if status, ok := r.Context().Value(StatusCtxKey).(int); ok { | ||
w.WriteHeader(status) | ||
} | ||
w.Write([]byte(v)) | ||
w.Write([]byte(v)) //nolint:errcheck | ||
} | ||
|
||
// JSON marshals 'v' to JSON, automatically escaping HTML and setting the | ||
|
@@ -103,7 +103,7 @@ func JSON(w http.ResponseWriter, r *http.Request, v interface{}) { | |
if status, ok := r.Context().Value(StatusCtxKey).(int); ok { | ||
w.WriteHeader(status) | ||
} | ||
w.Write(buf.Bytes()) | ||
w.Write(buf.Bytes()) //nolint:errcheck | ||
} | ||
|
||
// XML marshals 'v' to JSON, setting the Content-Type as application/xml. It | ||
|
@@ -128,15 +128,15 @@ func XML(w http.ResponseWriter, r *http.Request, v interface{}) { | |
} | ||
if !bytes.Contains(b[:findHeaderUntil], []byte("<?xml")) { | ||
// No header found. Print it out first. | ||
w.Write([]byte(xml.Header)) | ||
w.Write([]byte(xml.Header)) //nolint:errcheck | ||
} | ||
|
||
w.Write(b) | ||
w.Write(b) //nolint:errcheck | ||
} | ||
|
||
// NoContent returns a HTTP 204 "No Content" response. | ||
func NoContent(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(204) | ||
w.WriteHeader(http.StatusNoContent) | ||
} | ||
|
||
func channelEventStream(w http.ResponseWriter, r *http.Request, v interface{}) { | ||
|
@@ -153,7 +153,7 @@ func channelEventStream(w http.ResponseWriter, r *http.Request, v interface{}) { | |
w.Header().Set("Connection", "keep-alive") | ||
} | ||
|
||
w.WriteHeader(200) | ||
w.WriteHeader(http.StatusOK) | ||
|
||
ctx := r.Context() | ||
for { | ||
|
@@ -162,12 +162,12 @@ func channelEventStream(w http.ResponseWriter, r *http.Request, v interface{}) { | |
{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(v)}, | ||
}); chosen { | ||
case 0: // equivalent to: case <-ctx.Done() | ||
w.Write([]byte("event: error\ndata: {\"error\":\"Server Timeout\"}\n\n")) | ||
w.Write([]byte("event: error\ndata: {\"error\":\"Server Timeout\"}\n\n")) //nolint:errcheck | ||
return | ||
|
||
default: // equivalent to: case v, ok := <-stream | ||
if !ok { | ||
w.Write([]byte("event: EOF\n\n")) | ||
w.Write([]byte("event: EOF\n\n")) //nolint:errcheck | ||
return | ||
} | ||
v := recv.Interface() | ||
|
@@ -184,13 +184,13 @@ func channelEventStream(w http.ResponseWriter, r *http.Request, v interface{}) { | |
|
||
bytes, err := json.Marshal(v) | ||
if err != nil { | ||
w.Write([]byte(fmt.Sprintf("event: error\ndata: {\"error\":\"%v\"}\n\n", err))) | ||
w.Write([]byte(fmt.Sprintf("event: error\ndata: {\"error\":\"%v\"}\n\n", err))) //nolint:errcheck | ||
if f, ok := w.(http.Flusher); ok { | ||
f.Flush() | ||
} | ||
continue | ||
} | ||
w.Write([]byte(fmt.Sprintf("event: data\ndata: %s\n\n", bytes))) | ||
w.Write([]byte(fmt.Sprintf("event: data\ndata: %s\n\n", bytes))) //nolint:errcheck | ||
if f, ok := w.(http.Flusher); ok { | ||
f.Flush() | ||
} | ||
|
@@ -209,7 +209,7 @@ func channelIntoSlice(w http.ResponseWriter, r *http.Request, from interface{}) | |
{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(from)}, | ||
}); chosen { | ||
case 0: // equivalent to: case <-ctx.Done() | ||
http.Error(w, "Server Timeout", 504) | ||
http.Error(w, "Server Timeout", http.StatusGatewayTimeout) | ||
return nil | ||
|
||
default: // equivalent to: case v, ok := <-stream | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we bring in github.com/ajg/form as golang/dep dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a more global question for you, for the project. Currently there's no dependency tooling, so I didn't add any.