Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DatabaseCommand = &cobra.Command{ Use: "db", Short: "Make database operations", Long: "Make database operations: initialisation and dump", Run: func(cmd *cobra.Command, args []string) { color.Yellow(` |---------------------| | | | Database operations | | | |---------------------| `) if !lib.IsDatabaseConfigCorrect() { err := errors.New("no or missing database information in settings file") lib.CheckError(err, 1) } database.Open() defer database.DB.Close() if isInit { // Initialisation // -------------- var confirm = "Y" fmt.Println("If a database already exists, data will be deleted") fmt.Print("Do you really want to initialize database (Y/n): ") _, err := fmt.Scanf("%s", &confirm) if err != nil || confirm == "n" { fmt.Print("\n\n -> Database initialization: ") color.Yellow("Operation aborded\n\n") } else { fmt.Print("\n\n -> Database initialization: ") database.InitDatabase() color.Green("Success\n\n") } } else if isDump { fmt.Print(" -> Database dump: ") fileName, fileSize := database.DumpDatabase(dumpStructureOnly, dumpDataOnly) color.Green(fileName + " (" + bytefmt.ByteSize(uint64(fileSize)) + ") successfully created\n\n") } }, }
DatabaseCommand : Database command
View Source
var LogCommand = &cobra.Command{ Use: "logs-rotation", Short: "Make server logs rotation", Long: "Make server logs rotation", Run: func(cmd *cobra.Command, args []string) { color.Yellow(` |----------------------| | | | Server logs rotation | | | |----------------------| `) executeLogsRotation() }, }
LogCommand : Logs rotation command
View Source
var LogsExportCommand = &cobra.Command{ Use: "logs-export", Short: "Export logs in CSV files", Long: "Export logs in CSV files", Run: func(cmd *cobra.Command, args []string) { color.Yellow(` |-------------| | | | Logs export | | | |-------------| `) logs := make([]string, 0, 3) if logsAll { logs = append(logs, "access") logs = append(logs, "errors") logs = append(logs, "sql") } else { if logsAccess { logs = append(logs, "access") } if logsErrors { logs = append(logs, "errors") } if logsSql { logs = append(logs, "sql") } } if len(logs) == 0 { logs = append(logs, "access") logs = append(logs, "errors") logs = append(logs, "sql") logsAll = true } if logsCsvSeparator != "," && logsCsvSeparator != ";" && logsCsvSeparator != "tab" { } if logsCsvSeparator == "tab" { logsCsvSeparator = "\t" } exportLogs(logs) }, }
LogsExportCommand exports logs in CSV files
View Source
var MigrateCommand = &cobra.Command{ Use: "migrate", Short: "Make database migrations", Long: "Make database migrations", Run: func(cmd *cobra.Command, args []string) { color.Yellow(` |---------------------| | | | Database migrations | | | |---------------------| `) if force { fmt.Println("Connecting to GORM...") database.OpenORM() defer database.Orm.Close() lib.DisplaySuccessMessage("Connection OK\n") fmt.Println("\nStarting migrations...") database.Migrate(database.Orm) lib.DisplaySuccessMessage("Migrations OK\n") } else { fmt.Println("Use --force flag to make migrations") fmt.Println("") } }, }
MigrateCommand create database migration
View Source
var MigrationCommand = &cobra.Command{ Use: "make-migration", Short: "Create a database migration", Long: "Create a database migration", Run: func(cmd *cobra.Command, args []string) { color.Yellow(` |-----------------------------| | | | Database migration creation | | | |-----------------------------| `) if migrationFileName == "" { lib.CheckError(errors.New("migration file name cannot be empty"), 1) } timePrefix := time.Now().Format("20060102150405") migrationFileNamePath := migrationsPath + timePrefix + "_" + migrationFileName + ".go" functionName := "Migration" + timePrefix + migrationFileName err := createMigrationFile(migrationsPath, migrationFileNamePath, functionName, timePrefix) lib.CheckError(err, 1) err = updateMigrationsFile(functionName) lib.CheckError(err, 1) }, }
MigrationCommand create database migration
View Source
var ServerCommand = &cobra.Command{ Use: "serve", Short: "Launch the Web server", Run: func(cmd *cobra.Command, args []string) { color.Yellow(` |-------------------| | | | Launch Web server | | | |-------------------| `) fmt.Print("Version\t\t\t") color.Green(viper.GetString("version") + "\n") fmt.Print("Environment\t\t") color.Green(viper.GetString("environment") + "\n") port := viper.GetInt("server.port") if port < 10 || port > 10000 { lib.CheckError(errors.New("a valid port number must be configured (between 1000 and 10000)"), 1) } if !lib.IsDatabaseConfigCorrect() { lib.CheckError(errors.New("no or missing database information in settings file"), 1) } database.Open() defer database.DB.Close() fmt.Print("Connection to database \t") color.Green("✔\n") database.OpenORM() defer database.Orm.Close() fmt.Print("Connection to ORM \t") color.Green("✔\n\n") echo.StartServer() }, }
ServerCommand : Server command
View Source
var WebSocketCommand = &cobra.Command{ Use: "websocket", Short: "Launch the WebSocket server", Run: func(cmd *cobra.Command, args []string) { color.Yellow(` |--------------------------| | | | Launch WebSockets server | | | |--------------------------| `) port := viper.GetInt("webSocketServer.port") if port < 1000 || port > 10000 { lib.CheckError(errors.New("a valid port number must be configured (between 1000 and 10000)"), 1) } fmt.Print("Listening on port ") color.Green(strconv.Itoa(port) + "\n") database.OpenORM() defer database.Orm.Close() fmt.Print("Connection to ORM ") color.Green("✔\n\n") websockets.ServerStart() }, }
WebSocketCommand : Web command
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.