mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-22 06:40:43 +08:00
feat(ftp): support receive ftp connection (#6)
Co-authored-by: E99p1ant <[email protected]>
This commit is contained in:
+24
-5
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/li4n0/revsuit/internal/database"
|
||||
"github.com/li4n0/revsuit/internal/notice"
|
||||
"github.com/li4n0/revsuit/pkg/dns"
|
||||
"github.com/li4n0/revsuit/pkg/ftp"
|
||||
"github.com/li4n0/revsuit/pkg/mysql"
|
||||
http "github.com/li4n0/revsuit/pkg/rhttp"
|
||||
"github.com/li4n0/revsuit/pkg/rmi"
|
||||
@@ -13,10 +14,13 @@ import (
|
||||
)
|
||||
|
||||
type Revsuit struct {
|
||||
logLevel log.Level
|
||||
|
||||
http *http.Server
|
||||
dns *dns.Server
|
||||
mysql *mysql.Server
|
||||
rmi *rmi.Server
|
||||
ftp *ftp.Server
|
||||
}
|
||||
|
||||
func initDatabase(dsn string) {
|
||||
@@ -61,11 +65,18 @@ func initDatabase(dsn string) {
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
err = database.DB.AutoMigrate(&ftp.Record{})
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
err = database.DB.AutoMigrate(&ftp.Rule{})
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func initLog(level string) {
|
||||
var logLevel log.Level
|
||||
func initLog(level string) (logLevel log.Level) {
|
||||
|
||||
switch level {
|
||||
case "debug":
|
||||
@@ -93,7 +104,7 @@ func initLog(level string) {
|
||||
log.ConsoleConfig{
|
||||
Level: logLevel,
|
||||
})
|
||||
|
||||
return logLevel
|
||||
}
|
||||
|
||||
func initNotice(nc noticeConfig) {
|
||||
@@ -123,11 +134,12 @@ func initNotice(nc noticeConfig) {
|
||||
func New(c *Config) *Revsuit {
|
||||
|
||||
initDatabase(c.Database)
|
||||
initLog(c.LogLevel)
|
||||
logLevel := initLog(c.LogLevel)
|
||||
initNotice(c.Notice)
|
||||
|
||||
s := &Revsuit{
|
||||
http: http.GetServer(),
|
||||
logLevel: logLevel,
|
||||
http: http.GetServer(),
|
||||
}
|
||||
if c.DNS.Enable {
|
||||
s.dns = dns.GetServer()
|
||||
@@ -140,6 +152,10 @@ func New(c *Config) *Revsuit {
|
||||
s.rmi = rmi.GetServer()
|
||||
s.rmi.Config = c.RMI
|
||||
}
|
||||
if c.FTP.Enable {
|
||||
s.ftp = ftp.GetServer()
|
||||
s.ftp.Config = c.FTP
|
||||
}
|
||||
|
||||
if c.Addr != "" {
|
||||
s.http.SetAddr(c.Addr)
|
||||
@@ -166,6 +182,9 @@ func (revsuit *Revsuit) Run() {
|
||||
if revsuit.rmi != nil {
|
||||
go revsuit.rmi.Run()
|
||||
}
|
||||
if revsuit.ftp != nil {
|
||||
go revsuit.ftp.Run()
|
||||
}
|
||||
|
||||
revsuit.http.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user