Showing
5 changed files
with
49 additions
and
1 deletions
| ... | @@ -34,4 +34,5 @@ | ... | @@ -34,4 +34,5 @@ |
| 34 | # End of https://www.toptal.com/developers/gitignore/api/go,vscode | 34 | # End of https://www.toptal.com/developers/gitignore/api/go,vscode |
| 35 | 35 | ||
| 36 | __debug_bin | 36 | __debug_bin |
| 37 | -config.json | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 37 | +config.json | ||
| 38 | +data | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -32,6 +32,7 @@ func NewApp(config Config) *App { | ... | @@ -32,6 +32,7 @@ func NewApp(config Config) *App { |
| 32 | app.router = mux.NewRouter() | 32 | app.router = mux.NewRouter() |
| 33 | app.router.HandleFunc("/users", app.PostUsers).Methods("POST") | 33 | app.router.HandleFunc("/users", app.PostUsers).Methods("POST") |
| 34 | app.router.HandleFunc("/users/tokens", app.PostTokens).Methods("POST") | 34 | app.router.HandleFunc("/users/tokens", app.PostTokens).Methods("POST") |
| 35 | + app.router.Handle("/extractions", app.WithAuth(app.PostExtractions)).Methods("Post") | ||
| 35 | 36 | ||
| 36 | return app | 37 | return app |
| 37 | } | 38 | } | ... | ... |
source/server/extraction.go
0 → 100644
| 1 | +package main | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "io" | ||
| 6 | + "net/http" | ||
| 7 | + "os" | ||
| 8 | + "strings" | ||
| 9 | + | ||
| 10 | + "github.com/google/uuid" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +func (app *App) PostExtractions(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + userNo := r.Context().Value(PropUserNo).(uint64) | ||
| 15 | + r.ParseMultipartForm(32 << 20) | ||
| 16 | + | ||
| 17 | + form, _, err := r.FormFile("file") | ||
| 18 | + if err != nil { | ||
| 19 | + WriteError(w, http.StatusInternalServerError, "Unknown error") | ||
| 20 | + return | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + defer form.Close() | ||
| 24 | + | ||
| 25 | + dir := fmt.Sprintf("data/%d", userNo) | ||
| 26 | + os.MkdirAll(dir, 0644) | ||
| 27 | + | ||
| 28 | + name := strings.Replace(uuid.New().String(), "-", "", -1) | ||
| 29 | + file, err := os.Create(fmt.Sprintf("%s/%s", dir, name)) | ||
| 30 | + if err != nil { | ||
| 31 | + WriteError(w, http.StatusInternalServerError, "Unknown error") | ||
| 32 | + return | ||
| 33 | + } | ||
| 34 | + defer file.Close() | ||
| 35 | + | ||
| 36 | + _, err = io.Copy(file, form) | ||
| 37 | + if err != nil { | ||
| 38 | + WriteError(w, http.StatusInternalServerError, "Unknown error") | ||
| 39 | + return | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + w.Write([]byte("success")) | ||
| 43 | +} |
| ... | @@ -5,6 +5,7 @@ go 1.15 | ... | @@ -5,6 +5,7 @@ go 1.15 |
| 5 | require ( | 5 | require ( |
| 6 | github.com/dgrijalva/jwt-go v3.2.0+incompatible | 6 | github.com/dgrijalva/jwt-go v3.2.0+incompatible |
| 7 | github.com/go-sql-driver/mysql v1.5.0 | 7 | github.com/go-sql-driver/mysql v1.5.0 |
| 8 | + github.com/google/uuid v1.1.2 | ||
| 8 | github.com/gorilla/mux v1.8.0 | 9 | github.com/gorilla/mux v1.8.0 |
| 9 | github.com/jmoiron/sqlx v1.2.0 | 10 | github.com/jmoiron/sqlx v1.2.0 |
| 10 | golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 | 11 | golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 | ... | ... |
| ... | @@ -4,6 +4,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm | ... | @@ -4,6 +4,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm |
| 4 | github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= | 4 | github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= |
| 5 | github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= | 5 | github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= |
| 6 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= | 6 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= |
| 7 | +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= | ||
| 8 | +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
| 7 | github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= | 9 | github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= |
| 8 | github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= | 10 | github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= |
| 9 | github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= | 11 | github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= | ... | ... |
-
Please register or login to post a comment