-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (44 loc) · 1.68 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"log"
"net/http"
"os"
"time"
"github.com/gorilla/mux"
)
var debug = os.Getenv("DEBUG") == "true"
func main() {
listen := os.Getenv("LISTEN")
if listen == "" {
listen = ":8080"
}
setupHandlers()
setupS3()
router := mux.NewRouter()
router.Use(middlewareLogger)
router.Methods(http.MethodGet).Path("/readyz").HandlerFunc(readyz)
router.Methods(http.MethodGet).PathPrefix("/assets").HandlerFunc(handleAssets)
router.Methods(http.MethodGet).Path("/").HandlerFunc(handleCreate)
router.Methods(http.MethodPost).Path("/").HandlerFunc(handleCreateForm)
router.Methods(http.MethodGet).Path("/help").HandlerFunc(handleHelp)
uploadRouter := router.PathPrefix("/{id}").Subrouter()
uploadTemplateRouter := uploadRouter.Path("").Subrouter()
s3Router := uploadRouter.PathPrefix("/s3/multipart").Subrouter()
uploadTemplateRouter.Methods(http.MethodGet).Path("").HandlerFunc(handleUpload)
s3Router.Methods(http.MethodPost).Path("").HandlerFunc(handleCreateMultipartUpload)
s3Router.Methods(http.MethodGet).Path("/{uploadID}").HandlerFunc(handleGetUploadedParts)
s3Router.Methods(http.MethodGet).Path("/{uploadID}/batch").HandlerFunc(handleBatchSignPartsUpload)
s3Router.Methods(http.MethodGet).Path("/{uploadID}/{uploadPart}").HandlerFunc(handleSignPartUpload)
s3Router.Methods(http.MethodPost).Path("/{uploadID}/complete").HandlerFunc(handleCompleteMultipartUpload)
s3Router.Methods(http.MethodDelete).Path("/{uploadID}").HandlerFunc(handleAbortMultipartUpload)
server := &http.Server{
Handler: router,
Addr: listen,
ReadTimeout: 30 * time.Second,
}
log.Printf("listening on %s", listen)
err := server.ListenAndServe()
if err != nil {
panic(err)
}
}