commit 117e676cc73fd063a27d65019115d430f6c30191 Author: AsuraEU Date: Thu Jul 20 15:18:01 2023 +0200 init diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..11fc498 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module todo + +go 1.20 diff --git a/main.go b/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/pkg/config/database.go b/pkg/config/database.go new file mode 100644 index 0000000..ecd2f92 --- /dev/null +++ b/pkg/config/database.go @@ -0,0 +1,72 @@ +package config + +import ( + "database/sql" + "errors" + "fmt" + "log" + "os" +) + +func Database() *sql.DB { + logger, _ := thoth.Init("log") + + user, exist := os.LookupEnv("DB_USER") + + if !exist { + logger.Log(errors.New("DB_USER not set in .env")) + log.Fatal("DB_USER not set in .env") + } + + pass, exist := os.LookupEnv("DB_PASS") + + if !exist { + logger.Log(errors.New("DB_PASS not set in .env")) + log.Fatal("DB_PASS not set in .env") + } + + host, exist := os.LookupEnv("DB_HOST") + + if !exist { + logger.Log(errors.New("DB_HOST not set in .env")) + log.Fatal("DB_HOST not set in .env") + } + + credentials := fmt.Sprintf("%s:%s@(%s:3306)/?charset=utf8&parseTime=True", user, pass, host) + + database, err := sql.Open("mysql", credentials) + + if err != nil { + logger.Log(err) + log.Fatal(err) + } else { + fmt.Println("Database Connection Successful") + } + + _, err = database.Exec(`CREATE DATABASE gotodo`) + + if err != nil { + fmt.Println(err) + } + + _, err = database.Exec(`USE gotodo`) + + if err != nil { + fmt.Println(err) + } + + _, err = database.Exec(` + CREATE TABLE todos ( + id INT AUTO_INCREMENT, + item TEXT NOT NULL, + completed BOOLEAN DEFAULT FALSE, + PRIMARY KEY (id) + ); + `) + + if err != nil { + fmt.Println(err) + } + + return database +} diff --git a/pkg/controllers/todo.go b/pkg/controllers/todo.go new file mode 100644 index 0000000..2d32936 --- /dev/null +++ b/pkg/controllers/todo.go @@ -0,0 +1 @@ +package controllers diff --git a/pkg/src/index.html b/pkg/src/index.html new file mode 100644 index 0000000..87bbf12 --- /dev/null +++ b/pkg/src/index.html @@ -0,0 +1,69 @@ + + + + + Todo + + + +

Todos

+ +
+
+
Add a task
+
+
+
+ + + Enter what you want to procastinate 🙂 +
+ +
+
+
+
+   +   +
+
+
Tasks
+
+ + + + + + + + + + {{range .Todos}} + {{if .Completed}} + + + + + + {{else}} + + + + + + {{end}} + {{end}} + +
ItemStatusAction
{{.Item}}Completed + + +
{{.Item}}Not Completed + + +
+
+
+
+ + \ No newline at end of file