Working post to Create OS
This commit is contained in:
@@ -102,6 +102,33 @@ func GetVersionByDistributionList(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(list)
|
||||
}
|
||||
|
||||
func CreateOS(w http.ResponseWriter, r *http.Request) {
|
||||
var os db.OS
|
||||
var err error
|
||||
|
||||
t := time.Now()
|
||||
status := 200
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Println("Error reading request body", err)
|
||||
}
|
||||
|
||||
params := make(map[string]null.String)
|
||||
json.Unmarshal(body, ¶ms)
|
||||
os.Distribution = params["distribution"]
|
||||
os.Version = params["version"]
|
||||
os.End_of_support = params["end_of_support"]
|
||||
db_conn := db.GetDatabaseConnection()
|
||||
err = db.CreateOS(os, db_conn)
|
||||
if err != nil {
|
||||
log.Println("Error creating new OS", err)
|
||||
status = 500
|
||||
}
|
||||
logRequest(t, r, status)
|
||||
w.WriteHeader(status)
|
||||
}
|
||||
|
||||
func logRequest(t time.Time, r *http.Request, s int) {
|
||||
log.Printf("%s - - %s \"%s %s %s\" %d 0 \"-\" \"%s\" %d\n",
|
||||
r.Host,
|
||||
|
||||
Reference in New Issue
Block a user