-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (34 loc) · 892 Bytes
/
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
package main
import (
"log"
"net/http"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
)
const (
AWS_S3_REGION = ""
AWS_S3_BUCKET = ""
AWS_KEY = ""
AWS_SECRET = ""
)
var sess = connectAWS()
func connectAWS() *session.Session {
sess, err := session.NewSession(&aws.Config{
Region: aws.String(AWS_S3_REGION),
Credentials: credentials.NewStaticCredentials(AWS_KEY, AWS_SECRET, ""),
})
if err != nil {
panic(err)
}
return sess
}
func main() {
http.HandleFunc("/upload/", handlerUpload) // Upload
http.HandleFunc("/get/", handlerDownload) // Get the file
http.HandleFunc("/list/", handlerList) // List all files
log.Fatal(http.ListenAndServe(":8080", nil))
}
func showError(w http.ResponseWriter, r *http.Request, status int, message string) {
http.Error(w, message, status)
}