-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
70 lines (60 loc) · 1.52 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/fclairamb/ftpserver/server"
"log"
"os"
"os/signal"
"strconv"
"syscall"
)
var (
ftpServer *server.FtpServer
driver *S3Driver
FTP_PORT_STR = os.Getenv("FTP_PORT")
FTP_PORT int
S3_BUCKET_NAME = os.Getenv("S3_BUCKET_NAME")
ROOT_PREFIX = os.Getenv("ROOT_PREFIX")
FTP_USER = os.Getenv("FTP_USER")
FTP_PASSWD = os.Getenv("FTP_PASSWD")
)
func init() {
switch "" {
case FTP_PORT_STR:
log.Fatal("Error: environment variable FTP_PORT is not set")
case S3_BUCKET_NAME:
log.Fatal("Error: environment variable S3_BUCKET_NAME is not set")
case FTP_USER:
log.Fatal("Error: environment variable FTP_USER is not set")
case FTP_PASSWD:
log.Fatal("Error: environment variable FTP_PASSWD is not set")
}
var err error
if FTP_PORT, err = strconv.Atoi(FTP_PORT_STR); err != nil {
log.Fatal("Error parsing FTP_PORT as an integer", err)
}
}
func main() {
var err error
var s3Session *session.Session
if s3Session, err = session.NewSession(); err != nil {
log.Fatal("error creating S3 session", err)
}
driver = NewS3Driver(s3Session, S3_BUCKET_NAME, ROOT_PREFIX, FTP_PORT, FTP_USER, FTP_PASSWD)
ftpServer = server.NewFtpServer(driver)
go signalHandler()
if err = ftpServer.ListenAndServe(); err != nil {
log.Println("Problem listening", err)
}
}
func signalHandler() {
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGTERM)
for {
switch <-ch {
case syscall.SIGTERM:
ftpServer.Stop()
break
}
}
}