i currently try to do a Fileserver for my Project.
i have to fill a Drop-down-menu with a struct-array, get the name back of the chosen one of the box and have to read the strings inside a textfield of HTML from Go and i dont know how to do that. Pls send me some Code Example cause im new to this language and dont understand much.
Here is my Go-Code:
//Klimakammer struct
type klimakammer struct {
name string
Hersteller string
ip string
sollTemp string
istTemp string
sollFcht string
istFcht string
kammerstart bool
kammerstop bool
}
//Ct01 Klimakammern erstellen
var Ct01 = klimakammer{"ct01", "weiss", "10.0.62.22", "", "", "", "", false, true}
//Kammern - Fill Klimakammer Array
var Kammern = []klimakammer{
Ct01,
}
func main() {
fs := http.FileServer(http.Dir("./static"))
http.Handle("/", fs)
http.ListenAndServe(":8080", nil)
http.HandleFunc("/getKammer", func(w http.ResponseWriter, r *http.Request) {
//The Struct-Array kammern should be passed here to the DropDown
})
}
And here is my Func.js Code: -> it’s an onClick Function when you start the program per button
function fillChoiceBox() {
var x = document.getElementById("Kammer"); // ID of DropDown
//Loop for Struct Array
var option = document.createElement("option");
option.text = //Every single Chamber/kammer as option like Ct01.name
x.add(option);
}