commit 96f4c52343fdd00511714d900cf82411b1e298e9 Author: alex Date: Sat Oct 7 21:27:57 2023 +0200 init project diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bf3072c --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module jannex/robot-control-manager + +go 1.21.0 + +require ( + github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/joho/godotenv v1.5.1 // indirect + gorm.io/driver/mysql v1.5.1 // indirect + gorm.io/gorm v1.25.4 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..37eec79 --- /dev/null +++ b/go.sum @@ -0,0 +1,13 @@ +github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= +github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw= +gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o= +gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw= +gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= diff --git a/main.go b/main.go new file mode 100644 index 0000000..02f56ae --- /dev/null +++ b/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + "jannex/robot-control-manager/modules/database" +) + +func init() { + database.InitDatabase() +} + +func main() { + fmt.Println("Hello, World!") +} diff --git a/modules/config/config.go b/modules/config/config.go new file mode 100644 index 0000000..45fc27a --- /dev/null +++ b/modules/config/config.go @@ -0,0 +1,50 @@ +package config + +import ( + "fmt" + "os" + + "github.com/joho/godotenv" +) + +var Cfg Config + +type Config struct { + Debug bool + ColorizedOutput bool + Host string + Port string + MariaDB MariaDB +} + +type MariaDB struct { + Hostname string + Port string + Username string + Password string + DatabaseName string +} + +func LoadConfig() { + // used to determine server was startet in docker or not + if os.Getenv("DOCKER") == "" { + fmt.Println("Load env from file") + godotenv.Load(".env") + } else { + fmt.Println("Load env from system") + } + + Cfg = Config{ + Debug: os.Getenv("DEBUG") == "true", + ColorizedOutput: os.Getenv("COLORIZED_OUTPUT") == "true", + Host: os.Getenv("HOST"), + Port: os.Getenv("PORT"), + MariaDB: MariaDB{ + Hostname: os.Getenv("MARIADB_HOSTNAME"), + Port: os.Getenv("MARIADB_PORT"), + Username: os.Getenv("MARIADB_USERNAME"), + Password: os.Getenv("MARIADB_PASSWORD"), + DatabaseName: os.Getenv("MARIADB_DATABASE_NAME"), + }, + } +} diff --git a/modules/database/database.go b/modules/database/database.go new file mode 100644 index 0000000..bd6096b --- /dev/null +++ b/modules/database/database.go @@ -0,0 +1,36 @@ +package database + +import ( + "fmt" + "jannex/robot-control-manager/modules/config" + + "gorm.io/driver/mysql" + "gorm.io/gorm" + "gorm.io/gorm/logger" +) + +var DB *gorm.DB + +func InitDatabase() { + cfg := config.Cfg + + var logMode logger.LogLevel + + if cfg.Debug { + logMode = logger.Error + } else { + logMode = logger.Silent + } + + db, err := gorm.Open(mysql.Open( + fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", cfg.MariaDB.Username, cfg.MariaDB.Password, cfg.MariaDB.Hostname, cfg.MariaDB.Port, cfg.MariaDB.DatabaseName)), + &gorm.Config{ + Logger: logger.Default.LogMode(logMode), + }) + + if err != nil { + panic(err) + } + + DB = db +} diff --git a/modules/structs/jobs.go b/modules/structs/jobs.go new file mode 100644 index 0000000..451a010 --- /dev/null +++ b/modules/structs/jobs.go @@ -0,0 +1,12 @@ +package structs + +type Jobs struct { + Id string + Name string + Tasks []Task +} + +type Task struct { + Id string + Name string +} diff --git a/modules/structs/printer.go b/modules/structs/printer.go new file mode 100644 index 0000000..a015c59 --- /dev/null +++ b/modules/structs/printer.go @@ -0,0 +1,7 @@ +package structs + +// 3d printer +type Printer struct { + Id string + Address string +} diff --git a/modules/structs/rex.go b/modules/structs/rex.go new file mode 100644 index 0000000..0737d61 --- /dev/null +++ b/modules/structs/rex.go @@ -0,0 +1,8 @@ +package structs + +type Rex struct { + Id string + Address string + JobId string + Task string +}