Separating server and client for reasons ...
This commit is contained in:
29
isolated/server/main.go
Normal file
29
isolated/server/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.hrafn.xyz/aether/notes/internal/repository"
|
||||
"git.hrafn.xyz/aether/notes/internal/store/sqlite"
|
||||
"git.hrafn.xyz/aether/notes/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
databasefile := flag.String("db", filepath.Join(os.Getenv("HOME"), "notes.db"), "Path to the SQLite database file")
|
||||
dbPath := *databasefile
|
||||
sqliteStore, err := sqlite.NewSQLiteStore(context.Background(), dbPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer sqliteStore.Close()
|
||||
repo := repository.NewNoteRepository(sqliteStore)
|
||||
s := server.GetServer(repo, log.Default())
|
||||
err = s.Start(":8080")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.hrafn.xyz/aether/notes/client"
|
||||
"git.hrafn.xyz/aether/notes/internal/repository"
|
||||
"git.hrafn.xyz/aether/notes/internal/store/sqlite"
|
||||
"git.hrafn.xyz/aether/notes/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
serverMode := flag.Bool("server", false, "Start the application in server mode")
|
||||
list := flag.Bool("list", false, "List all notes in the database")
|
||||
create := flag.Bool("create", false, "Create a new note")
|
||||
update := flag.Bool("update", false, "Update an existing note")
|
||||
delete := flag.Bool("delete", false, "Delete a note from the database")
|
||||
get := flag.Bool("get", false, "Get a note by ID")
|
||||
|
||||
databasefile := flag.String("db", filepath.Join(os.Getenv("HOME"), "notes.db"), "Path to the SQLite database file (only used in server mode)")
|
||||
id := flag.Int("id", 0, "ID of the note to get, update, or delete (only used with -get, -update, or -delete)")
|
||||
content := flag.String("content", "", "Content of the note to create or update (only used with -create or -update)")
|
||||
|
||||
flag.Parse()
|
||||
modes := map[string]bool{
|
||||
"server": *serverMode,
|
||||
"list": *list,
|
||||
"create": *create,
|
||||
"update": *update,
|
||||
@@ -42,7 +34,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
if enabledCount == 0 {
|
||||
log.Fatal("No mode specified. Use -server, -list, -create, -update, -delete, or -get.")
|
||||
log.Fatal("No mode specified. Use -list, -create, -update, -delete, or -get.")
|
||||
os.Exit(1)
|
||||
}
|
||||
if enabledCount > 1 {
|
||||
@@ -50,21 +42,6 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *serverMode {
|
||||
dbPath := *databasefile
|
||||
sqliteStore, err := sqlite.NewSQLiteStore(context.Background(), dbPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer sqliteStore.Close()
|
||||
repo := repository.NewNoteRepository(sqliteStore)
|
||||
s := server.GetServer(repo, log.Default())
|
||||
err = s.Start(":8080")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if *list {
|
||||
client.ListNotes()
|
||||
}
|
||||
43
justfile
43
justfile
@@ -1,5 +1,7 @@
|
||||
# Use 'just <command>' to run tasks
|
||||
|
||||
build_path := "_build"
|
||||
server_exec_name := "server"
|
||||
simplecli_exec_name := "simplecli"
|
||||
|
||||
# Default recipe (runs when you just type 'just')
|
||||
default:
|
||||
@@ -7,10 +9,20 @@ default:
|
||||
|
||||
build: clean
|
||||
@echo "Building notes..."
|
||||
@mkdir -p _build
|
||||
go build -o _build/notes -ldflags="-s -w" .
|
||||
chmod +x ./_build/notes
|
||||
@echo "Build complete: ./_build/notes"
|
||||
@mkdir -p {{ build_path }}
|
||||
@just build-server
|
||||
@just build-simplecli
|
||||
|
||||
build-server:
|
||||
@echo "Building the isolated server..."
|
||||
@rm -f {{ build_path }}/{{ server_exec_name }}
|
||||
go build -o {{ build_path }}/{{ server_exec_name }} -ldflags="-s -w" isolated/server/main.go
|
||||
|
||||
build-simplecli:
|
||||
@echo "Building the simple cli..."
|
||||
@rm -f {{ build_path }}/{{ simplecli_exec_name }}
|
||||
go build -o {{ build_path }}/{{ simplecli_exec_name }} -ldflags="-s -w" isolated/simplecli/main.go
|
||||
|
||||
|
||||
# Run tests with short output
|
||||
test:
|
||||
@@ -21,12 +33,12 @@ test:
|
||||
# Run tests with coverage
|
||||
test-coverage:
|
||||
@echo "Running tests with coverage..."
|
||||
@mkdir -p _build
|
||||
@rm -f _build/coverage.out
|
||||
go test -v -coverprofile=_build/coverage.out ./...
|
||||
@mkdir -p {{ build_path }}
|
||||
@rm -f {{ build_path }}/coverage.out
|
||||
go test -v -coverprofile={{ build_path }}/coverage.out ./...
|
||||
@echo "Generate HTML report"
|
||||
go tool cover -html=_build/coverage.out -o _build/coverage.html
|
||||
@echo "Coverage report generated: _build/coverage.html"
|
||||
go tool cover -html={{ build_path }}/coverage.out -o {{ build_path }}/coverage.html
|
||||
@echo "Coverage report generated: {{ build_path }}/coverage.html"
|
||||
|
||||
# Watch for changes and run tests automatically
|
||||
watch:
|
||||
@@ -34,17 +46,8 @@ watch:
|
||||
@command -v watchexec >/dev/null 2>&1 || (echo "Error: watchexec not installed. Install with: brew install watchexec" && exit 1)
|
||||
@watchexec --clear --exts go -- sh -c 'echo "Changes detected, running tests..." && just test'
|
||||
|
||||
# Run the server
|
||||
run:
|
||||
@echo "Starting notes server..."
|
||||
go run . --server
|
||||
|
||||
# Run the built binary
|
||||
run-binary: build
|
||||
./_build/notes --server
|
||||
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
@echo "Cleaning build artifacts..."
|
||||
rm -rf _build
|
||||
rm -rf {{ build_path }}
|
||||
@echo "Clean complete"
|
||||
Reference in New Issue
Block a user