Exemple #1
0
// Network HTTP handler
func Network(w http.ResponseWriter, r *http.Request) {
	authd, user := auth.Check(w, r)
	if !authd {
		errors.Write(w, errors.NotAuthenticated)
		return
	}

	args := strings.Split(r.RequestURI, "/")[2:]
	switch r.Method {
	case http.MethodDelete:
		deleteNetwork(w, r, args, user)
	case http.MethodPut:
		addNetwork(w, r, args, user)
	case http.MethodPost:
		editNetwork(w, r, args, user)
	default:
		w.Header().Add("Allow", http.MethodDelete+","+http.MethodPut+","+http.MethodPost)
		errors.Write(w, errors.InvalidMethod)
	}
}
Exemple #2
0
// Script HTTP handler
func Script(w http.ResponseWriter, r *http.Request) {
	authd, user := auth.Check(w, r)
	if !authd {
		errors.Write(w, errors.NotAuthenticated)
		return
	}

	args := strings.Split(r.RequestURI, "/")[2:]
	switch r.Method {
	case http.MethodGet:
		getScripts(w, r, args, user)
	case http.MethodDelete:
		deleteScript(w, r, args, user)
	case http.MethodPut:
		putScript(w, r, args, user)
	case http.MethodPost:
		postScript(w, r, args, user)
	default:
		w.Header().Add("Allow", strings.Join([]string{http.MethodGet, http.MethodDelete, http.MethodPut, http.MethodPost}, ","))
		errors.Write(w, errors.InvalidMethod)
	}
}