-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add info about version. * Fix lint. * Move 'cmd/internal' package to the project root as 'internal' package. * Add '/version' HTTP route to the applications HTTP APIs. * Fix gosec warning.
- Loading branch information
Showing
11 changed files
with
80 additions
and
7 deletions.
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
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
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
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,27 @@ | ||
package internal | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"html" | ||
"net/http" | ||
) | ||
|
||
var version = "v0.0.0" | ||
|
||
// Version returns the version of the application. | ||
func Version() string { return version } | ||
|
||
func VersionHTTPHandler(w http.ResponseWriter, _ *http.Request) { | ||
type resp struct { | ||
Version string `json:"version"` | ||
} | ||
h := w.Header() | ||
h.Set("Content-Type", "application/json") | ||
h.Set("X-Content-Type-Options", "nosniff") | ||
if err := json.NewEncoder(w).Encode(resp{Version: Version()}); err != nil { | ||
msg := fmt.Sprintf("{\"error\":%q}\n", html.EscapeString(err.Error())) | ||
http.Error(w, msg, http.StatusInternalServerError) | ||
return | ||
} | ||
} |
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 @@ | ||
package internal_test | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"nodemon/internal" | ||
) | ||
|
||
func TestVersionHTTPHandler(t *testing.T) { | ||
r := httptest.NewRecorder() | ||
internal.VersionHTTPHandler(r, nil) | ||
assert.Equal(t, http.StatusOK, r.Code) | ||
h := r.Header() | ||
assert.Equal(t, "application/json", h.Get("Content-Type")) | ||
assert.Equal(t, "nosniff", h.Get("X-Content-Type-Options")) | ||
body := r.Body.Bytes() | ||
assert.True(t, json.Valid(body)) | ||
assert.Equal(t, "{\"version\":\"v0.0.0\"}\n", string(body)) | ||
} |
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