Working json return for OSes list
This commit is contained in:
parent
895fdedfe5
commit
316a1996c2
@ -1,6 +1,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
db "infra-dashboard/Database"
|
||||
opsys "infra-dashboard/OS"
|
||||
@ -21,16 +22,24 @@ func HealthHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
}
|
||||
|
||||
func GetOS(w http.ResponseWriter, r *http.Request) {
|
||||
var list []opsys.OS
|
||||
var err error
|
||||
|
||||
t := time.Now()
|
||||
status := 200
|
||||
|
||||
db_conn := db.GetDatabaseConnection()
|
||||
list, err := opsys.GetOS(db_conn)
|
||||
defer db_conn.Close()
|
||||
list, err = opsys.GetOS(db_conn)
|
||||
if err != nil {
|
||||
log.Println("Error getting OS list")
|
||||
status = 500
|
||||
}
|
||||
log.Println("list: ", list)
|
||||
|
||||
logRequest(t, r, 200)
|
||||
fmt.Fprint(w, "Hello, World!")
|
||||
logRequest(t, r, status)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(list)
|
||||
}
|
||||
|
||||
func logRequest(t time.Time, r *http.Request, s int) {
|
||||
|
||||
@ -28,5 +28,5 @@ func GetOS(db *sql.DB) ([]OS, error) {
|
||||
}
|
||||
oses = append(oses, os)
|
||||
}
|
||||
return oses, nil
|
||||
return oses, err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user