mirror of
https://forgejo.merr.is/annika/isl-api.git
synced 2025-12-11 14:28:48 -05:00
Mostly Initial Setup And Testing Stuff
This commit is contained in:
parent
8c147b23d8
commit
d52d9968ba
12 changed files with 502 additions and 0 deletions
41
main.go
Normal file
41
main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue