package server import ( "backend/util" "net/http" "strconv" ) func Start(port int64) { // Creating endpoints http.HandleFunc("/hello/", wrapHeader(handlePictureRequest)) util.Logformat(util.INFO, "Starting server on port %d...\n", port) if err := http.ListenAndServe(":"+strconv.FormatInt(port, 10), nil); err != nil { util.Logformat(util.ERROR, "Could not start server (%s)\n", err.Error()) panic(err) } } // Not sure about that, might change it later... (added by Lemonochrme on 'yoboujon/automatic-management') func wrapHeader(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "GET") w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") if r.Method == http.MethodOptions { w.WriteHeader(http.StatusOK) return } next(w, r) } }