-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
44 lines (36 loc) · 1.01 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
package main
import (
"fmt"
logrus_stack "github.com/Gurpartap/logrus-stack"
"github.com/pyama86/pftp/example/webapi"
"github.com/pyama86/pftp/pftp"
"github.com/sirupsen/logrus"
)
var confFile = "./config.toml"
func init() {
logrus.SetLevel(logrus.ErrorLevel)
stackLevels := []logrus.Level{logrus.PanicLevel, logrus.FatalLevel}
logrus.AddHook(logrus_stack.NewHook(stackLevels, stackLevels))
}
func main() {
ftpServer, err := pftp.NewFtpServer(confFile)
if err != nil {
logrus.Fatal(err)
}
ftpServer.Use("user", User)
if err := ftpServer.Start(); err != nil {
logrus.Fatal(err)
}
}
// User function will setup Origin ftp server domain from ftp username
// If failed get domain from server, the origin will set by local (localhost:21)
func User(c *pftp.Context, param string) error {
res, err := webapi.GetDomainFromWebAPI(confFile, param)
if err != nil {
logrus.Debug(fmt.Sprintf("cannot get origin host from webapi server:%v", err))
c.RemoteAddr = ""
} else {
c.RemoteAddr = *res
}
return nil
}