Compare commits
No commits in common. "29d5885b672a6b75d281a002a41ca5eb04122991" and "4de34e4adbafaeec249ecae3fede4ba4eec4c03e" have entirely different histories.
29d5885b67
...
4de34e4adb
8 changed files with 0 additions and 149 deletions
|
@ -1 +0,0 @@
|
||||||
# Time Management Platform
|
|
|
@ -1,50 +0,0 @@
|
||||||
# Go parameters
|
|
||||||
GOCMD = go
|
|
||||||
GOBUILD = $(GOCMD) build
|
|
||||||
GOCLEAN = $(GOCMD) clean
|
|
||||||
GOTEST = $(GOCMD) test
|
|
||||||
GOGET = $(GOCMD) get
|
|
||||||
|
|
||||||
# SQLite database filename
|
|
||||||
DB_FILE = db.sqlite3
|
|
||||||
|
|
||||||
# Directory containing migration SQL scripts
|
|
||||||
MIGRATIONS_DIR = migrations
|
|
||||||
|
|
||||||
# Build target
|
|
||||||
build:
|
|
||||||
$(GOBUILD) -o bin/server cmd/*.go
|
|
||||||
|
|
||||||
# Run target
|
|
||||||
run: build
|
|
||||||
./bin/server
|
|
||||||
|
|
||||||
# Clean target
|
|
||||||
clean:
|
|
||||||
$(GOCLEAN)
|
|
||||||
rm -f bin/server
|
|
||||||
rm -f db.sqlite3
|
|
||||||
|
|
||||||
# Test target
|
|
||||||
test:
|
|
||||||
$(GOTEST) ./...
|
|
||||||
|
|
||||||
# Get dependencies target
|
|
||||||
deps:
|
|
||||||
$(GOGET) -v ./...
|
|
||||||
|
|
||||||
# Update dependencies target
|
|
||||||
update:
|
|
||||||
$(GOGET) -u -v ./...
|
|
||||||
$(GOCMD) mod tidy
|
|
||||||
|
|
||||||
# Migration target
|
|
||||||
migrate:
|
|
||||||
@echo "Migrating database $(DB_FILE) using SQL scripts in $(MIGRATIONS_DIR)"
|
|
||||||
@for file in $(wildcard $(MIGRATIONS_DIR)/*.sql); do \
|
|
||||||
echo "Applying migration: $$file"; \
|
|
||||||
sqlite3 $(DB_FILE) < $$file; \
|
|
||||||
done
|
|
||||||
|
|
||||||
# Default target
|
|
||||||
default: build
|
|
|
@ -1,32 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"tmp/internal/database"
|
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
)
|
|
||||||
|
|
||||||
// This is what a handler looks like
|
|
||||||
func handler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
fmt.Println("Request received")
|
|
||||||
io.WriteString(w, "This is my website!\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
println("Starting server...")
|
|
||||||
database.DbConnect()
|
|
||||||
|
|
||||||
// Mounting the handler
|
|
||||||
fs := http.FileServer(http.Dir("static"))
|
|
||||||
http.Handle("/", fs)
|
|
||||||
http.HandleFunc("/hello", handler)
|
|
||||||
|
|
||||||
// Start the server on port 8080
|
|
||||||
err := http.ListenAndServe(":8080", nil)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
module tmp
|
|
||||||
|
|
||||||
go 1.21.1
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/jmoiron/sqlx v1.3.5
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.22
|
|
||||||
)
|
|
|
@ -1,9 +0,0 @@
|
||||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
|
||||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
|
||||||
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
|
|
||||||
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
|
|
||||||
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
|
|
||||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
|
|
@ -1,32 +0,0 @@
|
||||||
package database
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
)
|
|
||||||
|
|
||||||
func DbConnect() *sqlx.DB {
|
|
||||||
// Check for the environment variable
|
|
||||||
dbpath := os.Getenv("SQLITE_DB_PATH")
|
|
||||||
|
|
||||||
// Default to something reasonable
|
|
||||||
if dbpath == "" {
|
|
||||||
dbpath = "./db.sqlite3"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open the database
|
|
||||||
// db, err := sqlx.Connect("sqlite3", ":memory:")
|
|
||||||
db, err := sqlx.Connect("sqlite3", dbpath)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.Ping()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return db
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package database
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDbConnect(t *testing.T) {
|
|
||||||
db := DbConnect()
|
|
||||||
_ = db
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
PRAGMA foreign_keys = ON;
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
username VARCHAR(255) NOT NULL,
|
|
||||||
password VARCHAR(255) NOT NULL
|
|
||||||
);
|
|
Loading…
Reference in a new issue