refactor
This commit is contained in:
37
client/testfunc/testjson.go
Normal file
37
client/testfunc/testjson.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package testfunc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"git.dubyatp.xyz/orphanage/client/httputil"
|
||||
)
|
||||
|
||||
type TestResponse struct {
|
||||
APIVersion string `json:"apiVersion"`
|
||||
TestMessage string `json:"testMessage"`
|
||||
}
|
||||
|
||||
func (m TestResponse) MarshalJSON() ([]byte, error) {
|
||||
type OrderedTestResponse struct {
|
||||
APIVersion string `json:"apiVersion"`
|
||||
TestMessage string `json:"testMessage"`
|
||||
}
|
||||
|
||||
ordered := OrderedTestResponse{
|
||||
APIVersion: m.APIVersion,
|
||||
TestMessage: m.TestMessage,
|
||||
}
|
||||
|
||||
return json.Marshal(ordered)
|
||||
}
|
||||
|
||||
func HelloWorldJSON(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
resp := TestResponse{
|
||||
APIVersion: "v1",
|
||||
TestMessage: "this is a test owo",
|
||||
}
|
||||
httputil.WriteJSON(w, http.StatusOK, resp)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user