package routes import ( "fmt" "net/http" "strings" "time" "git.1e99.eu/1e99/wolbodge/sessions" ) func APIStartSession(storage sessions.Storage) http.HandlerFunc { return func(res http.ResponseWriter, req *http.Request) { err := req.ParseMultipartForm(10 * 1024) if err != nil { http.Error(res, "", http.StatusBadRequest) return } description := req.FormValue("description") if strings.TrimSpace(description) == "" { description = "description" } session, err := storage.StartSession(description, time.Now()) if err != nil { http.Error(res, "", http.StatusInternalServerError) return } fmt.Fprintf(res, "%s", session.Id) } } func APIEndSession(storage sessions.Storage) http.HandlerFunc { return func(res http.ResponseWriter, req *http.Request) { sessionId := req.PathValue("session_id") err := storage.EndSession(sessionId) if err != nil { http.Error(res, "", http.StatusInternalServerError) return } } }