sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost/cmd/warehost-ftp/main.go

71 lines
1.8 KiB
Go
Raw Permalink Normal View History

package main
import (
"database/sql"
"flag"
ftpd "github.com/goftp/server"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
liblog "dev.sum7.eu/sum7/warehost/lib/log"
host "dev.sum7.eu/sum7/warehost/modul/host"
web "dev.sum7.eu/sum7/warehost/modul/web"
system "dev.sum7.eu/sum7/warehost/system"
)
var (
configFile string
dbconnection *gorm.DB
dbDB *sql.DB
config *Config
)
func main() {
var err error
flag.StringVar(&configFile, "c", "config.yml", "path of configuration file")
flag.Parse()
config = ReadConfigFile(configFile)
liblog.NewLogger(config.Log.Path)
// Main Databaseconnection
dbconnection, err = gorm.Open("postgres", config.Database)
if err != nil {
liblog.Log.Fatal("database connection: ", err)
}
defer dbconnection.Close()
dbconnection.Callback().Create().Remove("gorm:update_time_stamp")
dbconnection.Callback().Update().Remove("gorm:update_time_stamp")
dbconnection.SingularTable(true)
dbconnection.LogMode(config.DatabaseDebug)
//load system Models to database
system.SyncModels(dbconnection)
host.SyncModels(dbconnection)
web.SyncModels(dbconnection)
opt := &ftpd.ServerOpts{
Name: "",
2016-12-19 12:52:43 +01:00
Factory: &FileDriverFactory{config: config, db: dbconnection, Perm: ftpd.NewSimplePerm("warehost", "http")},
Port: config.Port,
Auth: WarehostAuth{db: dbconnection},
}
2017-05-05 23:03:42 +02:00
if config.WelcomeMessage != "" {
opt.WelcomeMessage = config.WelcomeMessage
}
if config.SSL.Private != "" && config.SSL.Public != "" {
opt.TLS = true
opt.CertFile = config.SSL.Public
opt.KeyFile = config.SSL.Private
}
// start ftp server
ftpServer := ftpd.NewServer(opt)
liblog.Log.Info("warehost-ftp")
err = ftpServer.ListenAndServe()
if err != nil {
liblog.Log.Fatal("Error starting server:", err)
}
}