|
|
@ -22,6 +22,7 @@ func (db *DB) GetEverything() ([]*randomdata.RandomData, error) { |
|
|
|
var id uint |
|
|
|
var id uint |
|
|
|
var title string |
|
|
|
var title string |
|
|
|
var text string |
|
|
|
var text string |
|
|
|
|
|
|
|
|
|
|
|
rows.Scan(&id, &title, &text) |
|
|
|
rows.Scan(&id, &title, &text) |
|
|
|
|
|
|
|
|
|
|
|
var randomData = randomdata.RandomData{ |
|
|
|
var randomData = randomdata.RandomData{ |
|
|
@ -30,8 +31,6 @@ func (db *DB) GetEverything() ([]*randomdata.RandomData, error) { |
|
|
|
Text: text, |
|
|
|
Text: text, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println(id, title, text) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contents = append(contents, &randomData) |
|
|
|
contents = append(contents, &randomData) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -88,17 +87,28 @@ func (db *DB) HandleGlobalWeb(w http.ResponseWriter, r *http.Request) { |
|
|
|
log.Printf("Could not create a row: %s", err) |
|
|
|
log.Printf("Could not create a row: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
w.WriteHeader(http.StatusAccepted) |
|
|
|
w.WriteHeader(http.StatusAccepted) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
case http.MethodGet: |
|
|
|
case http.MethodGet: |
|
|
|
data, err := db.GetEverything() |
|
|
|
randomDatas, err := db.GetEverything() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
log.Printf("Could not retrieve db contents: %s\n", err) |
|
|
|
log.Printf("Could not retrieve db contents: %s\n", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
w.Write() |
|
|
|
randomDatasJsonBytes, err := randomdata.ToJsonAll(randomDatas) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
|
|
|
log.Printf("Could not convert to json: %s\n", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w.Write(randomDatasJsonBytes) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed) |
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|