Created
October 9, 2017 01:35
-
-
Save mickelsonm/3984656ce1cc714c1e8aa977e7ef8fb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.HandleFunc("/import", func(w http.ResponseWriter, r *http.Request) { | |
if r.Method != http.MethodPost { | |
http.Error(w, "error: invalid method", http.StatusBadRequest) | |
return | |
} | |
edata, err := ioutil.ReadAll(r.Body) | |
if err != nil { | |
log.Printf("Error reading request body: %v\n", err) | |
http.Error(w, "error: reading file", http.StatusInternalServerError) | |
return | |
} | |
efile, err := xlsx.OpenBinary(edata) | |
if err != nil { | |
log.Printf("Error opening binary: %v\n", err) | |
http.Error(w, "error: opening excel file", http.StatusInternalServerError) | |
return | |
} | |
sheet := efile.Sheets[0] | |
toJSON(w, sheet.Rows) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment