|
@@ -46,6 +46,9 @@ var (
|
|
|
debugFlag = false
|
|
|
preforkFlag = false
|
|
|
childFlag = false
|
|
|
+
|
|
|
+ helloWorldMessage = &Message{helloWorldString}
|
|
|
+ extraFortune = &Fortune{Message: extraFortuneMessage}
|
|
|
)
|
|
|
|
|
|
// Message is a JSON struct to render a message
|
|
@@ -53,8 +56,8 @@ type Message struct {
|
|
|
Message string
|
|
|
}
|
|
|
|
|
|
-// MarshalObject encodes the message as JSON
|
|
|
-func (m *Message) MarshalObject(dec *gojay.Encoder) {
|
|
|
+// MarshalJSONObject encodes the message as JSON
|
|
|
+func (m *Message) MarshalJSONObject(dec *gojay.Encoder) {
|
|
|
dec.AddStringKey("message", m.Message)
|
|
|
}
|
|
|
|
|
@@ -72,8 +75,8 @@ type World struct {
|
|
|
// Worlds is a list of World
|
|
|
type Worlds []World
|
|
|
|
|
|
-// MarshalArray marshals the list of worlds
|
|
|
-func (ws Worlds) MarshalArray(enc *gojay.Encoder) {
|
|
|
+// MarshalJSONArray marshals the list of worlds
|
|
|
+func (ws Worlds) MarshalJSONArray(enc *gojay.Encoder) {
|
|
|
for _, w := range ws {
|
|
|
enc.AddObject(&w)
|
|
|
}
|
|
@@ -84,8 +87,8 @@ func (ws Worlds) IsNil() bool {
|
|
|
return ws == nil
|
|
|
}
|
|
|
|
|
|
-// MarshalObject encodes the message as JSON
|
|
|
-func (w *World) MarshalObject(dec *gojay.Encoder) {
|
|
|
+// MarshalJSONObject encodes the message as JSON
|
|
|
+func (w *World) MarshalJSONObject(dec *gojay.Encoder) {
|
|
|
dec.AddIntKey("id", int(w.ID))
|
|
|
dec.AddIntKey("randomNumber", int(w.RandomNumber))
|
|
|
}
|
|
@@ -128,7 +131,7 @@ func setContentType(w http.ResponseWriter, contentType string) {
|
|
|
func serializeJSON(w http.ResponseWriter, r *http.Request) {
|
|
|
setContentType(w, "application/json")
|
|
|
|
|
|
- _ = gojay.NewEncoder(w).Encode(&Message{helloWorldString})
|
|
|
+ _ = gojay.NewEncoder(w).Encode(helloWorldMessage)
|
|
|
}
|
|
|
|
|
|
// Test 2: Single Database Query
|
|
@@ -190,7 +193,7 @@ func fortunes(w http.ResponseWriter, r *http.Request) {
|
|
|
fortunes = append(fortunes, &fortune)
|
|
|
}
|
|
|
rows.Close()
|
|
|
- fortunes = append(fortunes, &Fortune{Message: extraFortuneMessage})
|
|
|
+ fortunes = append(fortunes, extraFortune)
|
|
|
|
|
|
sort.Slice(fortunes, func(i, j int) bool {
|
|
|
return fortunes[i].Message < fortunes[j].Message
|