init project
commit
96f4c52343
|
@ -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
|
||||
)
|
|
@ -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=
|
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"jannex/robot-control-manager/modules/database"
|
||||
)
|
||||
|
||||
func init() {
|
||||
database.InitDatabase()
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, World!")
|
||||
}
|
|
@ -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"),
|
||||
},
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package structs
|
||||
|
||||
type Jobs struct {
|
||||
Id string
|
||||
Name string
|
||||
Tasks []Task
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
Id string
|
||||
Name string
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package structs
|
||||
|
||||
// 3d printer
|
||||
type Printer struct {
|
||||
Id string
|
||||
Address string
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package structs
|
||||
|
||||
type Rex struct {
|
||||
Id string
|
||||
Address string
|
||||
JobId string
|
||||
Task string
|
||||
}
|
Loading…
Reference in New Issue