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: "", Factory: &FileDriverFactory{config: config, db: dbconnection, Perm: ftpd.NewSimplePerm("warehost", "http")}, Port: config.Port, Auth: WarehostAuth{db: dbconnection}, } // 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) } }