38 lines
786 B
Go
38 lines
786 B
Go
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)
|
|
})
|
|
}
|