示例#1
0
func handleUpldVldt(w http.ResponseWriter, r *http.Request) {

	//// Get rules from YAML config
	//TODO: need to move this out of handler function so that it is parsed just once. we need not parse it everytime the excel is send for validation.
	rules, err := helpers.GetRules()
	if err != nil { //Note: this is a 5XX error
		panic(err.Error())
		return
	}

	//// Upload xlsx
	filesList, err := helpers.Upload(r)
	if err != nil { //Note: this is a 5XX error
		panic(err.Error())
		return
	}

	//// do Validation
	res, err := helpers.Validation(filesList, rules)
	if err != nil { //Note: this is a 5XX error
		panic(err.Error())
		return
	}

	//// send Response
	jsonRes, _ := json.Marshal(res)  // prepare the combined response as json and
	fmt.Fprintln(w, string(jsonRes)) //send it back to client
}
示例#2
0
func handleUpld(w http.ResponseWriter, r *http.Request) {

	//// Upload xlsx
	filesList, err := helpers.Upload(r)
	if err != nil { //Note: this is a 5XX error
		panic(err.Error())
		return
	}

	res := []helpers.Data{}

	for _, f := range filesList {

		d, err := helpers.Load(f.SrvrFileName)
		if err != nil {
			fmt.Println("ERROR ERROR with helpers.Load()", err.Error())
			panic(err.Error())
			return
		}
		fmt.Println(d)

		data := helpers.Data{
			FileDetails: helpers.FileDetails{f.ClientFileName, f.SrvrFileName},
			Data:        d,
		}
		res = append(res, data)
	}

	//// send Response:
	jsonRes, _ := json.Marshal(res)  // prepare the combined response as json and
	fmt.Fprintln(w, string(jsonRes)) //send it back to client

}