diff --git a/dbHandle/handle.go b/dbHandle/handle.go index 21930af..e86efe0 100644 --- a/dbHandle/handle.go +++ b/dbHandle/handle.go @@ -155,13 +155,14 @@ func (db *DB) HandleGlobalWeb(w http.ResponseWriter, r *http.Request) { log.Printf("Could not retrieve db contents: %s\n", err) return } - randomDatasJsonBytes, err := randomdata.ToJsonAll(randomDatas, true) + randomDatasJsonBytes, err := randomdata.ToJsonAll(randomDatas) if err != nil { w.WriteHeader(http.StatusInternalServerError) log.Printf("Could not convert to json: %s\n", err) return } + w.Header().Add("content-type", "application/json") w.Write(randomDatasJsonBytes) default: @@ -197,6 +198,7 @@ func (db *DB) HandleSpecificWeb(w http.ResponseWriter, r *http.Request) { return } + w.Header().Add("content-type", "application/json") w.Write(rdJsonBytes) case http.MethodDelete: diff --git a/randomData/randomData.go b/randomData/randomData.go index 4979e47..436daa6 100644 --- a/randomData/randomData.go +++ b/randomData/randomData.go @@ -35,18 +35,10 @@ func (rd *RandomData) ToJson() ([]byte, error) { } // Convert all rdatas to []byte -func ToJsonAll(rdatas []*RandomData, addNewlines bool) ([]byte, error) { - var rdatasBytes []byte - for _, rdata := range rdatas { - jsonBytes, err := rdata.ToJson() - if err != nil { - return nil, err - } - rdatasBytes = append(rdatasBytes, jsonBytes...) - - if addNewlines { - rdatasBytes = append(rdatasBytes, 10) - } +func ToJsonAll(rdatas []*RandomData) ([]byte, error) { + rdatasBytes, err := json.Marshal(&rdatas) + if err != nil { + return nil, err } return rdatasBytes, nil