Mostly Initial Setup And Testing Stuff

This commit is contained in:
Annika Merris 2024-01-26 17:11:42 -05:00
parent 8c147b23d8
commit d52d9968ba
12 changed files with 502 additions and 0 deletions

41
main.go Normal file
View file

@ -0,0 +1,41 @@
package main
import (
"isl-api/Controllers"
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", index)
Controllers.SetPowerItemEndpoints(mux, "powerItem")
err := http.ListenAndServe(":3000", mux)
log.Fatal(err)
}
func index(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
// Common code for all requests can go here...
switch r.Method {
case http.MethodGet:
// Handle the GET request...
case http.MethodPost:
// Handle the POST request...
case http.MethodOptions:
w.Header().Set("Allow", "GET, POST, OPTIONS")
w.WriteHeader(http.StatusNoContent)
default:
w.Header().Set("Allow", "GET, POST, OPTIONS")
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
}
}