Exemplo n.º 1
0
Arquivo: file.go Projeto: ubs121/lerp
func Upload(w http.ResponseWriter, r *http.Request) {

	var (
		body []byte
		err  error
	)
	defer r.Body.Close()

	vars := mux.Vars(r)

	dir, file := filepath.Split(filepath.Join(conf.Conf["FileHome"], vars["path"]))

	log.Printf("File upload %s\n", vars["path"])

	if _, e := os.Stat(dir); os.IsNotExist(e) {
		err = os.MkdirAll(dir, 0700)
	}

	if err == nil {
		body, err = ioutil.ReadAll(r.Body)
		err = ioutil.WriteFile(dir+file, body, 0700)
	}

	rpc.WriteJson(r, w, "OK", err)
}
Exemplo n.º 2
0
Arquivo: file.go Projeto: ubs121/lerp
func Delete(w http.ResponseWriter, r *http.Request) {
	var err error
	vars := mux.Vars(r)

	filePath := conf.Conf["FileHome"] + "/" + vars["path"]
	log.Printf("File delete %s ", vars["path"])

	err = os.Remove(filePath)

	rpc.WriteJson(r, w, "OK", err)
}