Working on distribution routes to get data
This commit is contained in:
@@ -4,11 +4,12 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
db "infra-dashboard/Database"
|
||||
opsys "infra-dashboard/OS"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func RequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -22,7 +23,7 @@ func HealthHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
}
|
||||
|
||||
func GetOS(w http.ResponseWriter, r *http.Request) {
|
||||
var list []opsys.OS
|
||||
var list []db.OS
|
||||
var err error
|
||||
|
||||
t := time.Now()
|
||||
@@ -30,13 +31,70 @@ func GetOS(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
db_conn := db.GetDatabaseConnection()
|
||||
defer db_conn.Close()
|
||||
list, err = opsys.GetOS(db_conn)
|
||||
list, err = db.GetOS(db_conn)
|
||||
if err != nil {
|
||||
log.Println("Error getting OS list")
|
||||
status = 500
|
||||
}
|
||||
log.Println("list: ", list)
|
||||
logRequest(t, r, status)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(list)
|
||||
}
|
||||
|
||||
func GetOSbyID(w http.ResponseWriter, r *http.Request) {
|
||||
var os db.OS
|
||||
var err error
|
||||
|
||||
t := time.Now()
|
||||
status := 200
|
||||
|
||||
params := mux.Vars(r)
|
||||
db_conn := db.GetDatabaseConnection()
|
||||
defer db_conn.Close()
|
||||
os, err = db.GetOSbyID(db_conn, params["id"])
|
||||
if err != nil {
|
||||
log.Println("Error getting OS")
|
||||
status = 500
|
||||
}
|
||||
logRequest(t, r, status)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(os)
|
||||
}
|
||||
|
||||
func GetDistributionList(w http.ResponseWriter, r *http.Request) {
|
||||
var list []string
|
||||
var err error
|
||||
|
||||
t := time.Now()
|
||||
status := 200
|
||||
|
||||
db_conn := db.GetDatabaseConnection()
|
||||
defer db_conn.Close()
|
||||
list, err = db.GetDistributionList(db_conn)
|
||||
if err != nil {
|
||||
log.Println("Error getting distribution list")
|
||||
status = 500
|
||||
}
|
||||
logRequest(t, r, status)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(list)
|
||||
}
|
||||
|
||||
func GetVersionByDistributionList(w http.ResponseWriter, r *http.Request) {
|
||||
var list []string
|
||||
var err error
|
||||
|
||||
t := time.Now()
|
||||
status := 200
|
||||
|
||||
params := mux.Vars(r)
|
||||
db_conn := db.GetDatabaseConnection()
|
||||
defer db_conn.Close()
|
||||
list, err = db.GetVersionByDistributionList(db_conn, params["distribution"])
|
||||
if err != nil {
|
||||
log.Println("Error getting distribution list")
|
||||
status = 500
|
||||
}
|
||||
logRequest(t, r, status)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(list)
|
||||
|
||||
Reference in New Issue
Block a user