This repository has been archived by the owner on Apr 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
56 lines (50 loc) · 1.51 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 (
log2 "log"
"net/http"
"os"
"path/filepath"
"time"
"github.com/NYTimes/logrotate"
"github.com/apex/log"
"github.com/apex/log/handlers/cli"
"github.com/apex/log/handlers/multi"
"github.com/apex/log/handlers/text"
"github.com/kubectyl/kuber/remote"
"github.com/kubectyl/sftp-server/config"
"github.com/kubectyl/sftp-server/sftp"
)
// Configures the global logger for Zap so that we can call it from any location
// in the code without having to pass around a logger instance.
func initLogging() {
dir := config.Get().System.LogDirectory
p := filepath.Join(dir, "/sftp-server.log")
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
log2.Fatalf("sftp: could not create internal sftp server log directory: %s", err)
}
w, err := logrotate.NewFile(p)
if err != nil {
log2.Fatalf("failed to create server log: %s", err)
}
log.SetLevel(log.InfoLevel)
if config.Get().Debug {
log.SetLevel(log.DebugLevel)
}
log.SetHandler(multi.New(text.New(os.Stdout), cli.New(w.File)))
log.WithField("path", p).Info("writing log file to disk")
}
func main() {
initLogging()
pclient := remote.New(
config.Get().PanelLocation,
remote.WithCredentials(config.Get().AuthenticationTokenId, config.Get().AuthenticationToken),
remote.WithHttpClient(&http.Client{
Timeout: time.Second * time.Duration(config.Get().RemoteQuery.Timeout),
}),
)
// Run the SFTP server.
if err := sftp.New(pclient).Run(); err != nil {
log.WithError(err).Fatal("failed to initialize the sftp server")
return
}
}