new port, env based config, build script

This commit is contained in:
2025-10-28 20:39:23 +01:00
parent 4a3fe068a3
commit a0b97a856a
8 changed files with 101 additions and 52 deletions

View File

@@ -46,7 +46,7 @@ func Load() ClientConfiguration {
func Default() ClientConfiguration {
return ClientConfiguration{
Deamon: ClientDaemonConfiguration{
URL: "http://localhost:8080",
URL: "http://localhost:25697",
},
}
}

View File

@@ -6,8 +6,9 @@ import (
"fmt"
"mirror-sync/pkg/project"
_ "github.com/glebarez/go-sqlite"
"github.com/google/uuid"
_ "github.com/ncruces/go-sqlite3/driver"
_ "github.com/ncruces/go-sqlite3/embed"
)
type (
@@ -18,7 +19,7 @@ type (
func OpenDB(path string) (*Repository, error) {
// connect
db, err := sql.Open("sqlite", path)
db, err := sql.Open("sqlite3", "file:"+path)
if err != nil {
return nil, fmt.Errorf("failed to open database: %s", err)
}

View File

@@ -1,7 +1,6 @@
package main
import (
"flag"
"fmt"
"log/slog"
"mirror-sync/cmd/server/api"
@@ -10,12 +9,25 @@ import (
"mirror-sync/pkg/constants"
"os"
"runtime"
"strconv"
)
func main() {
var dbPath string
flag.StringVar(&dbPath, "db-path", "/var/lib/mirror-sync/data.db", "path to the sqlite database")
flag.Parse()
dbPath := os.Getenv("MIRRORSYNC_DB_PATH")
if len(dbPath) == 0 {
dbPath = "/var/lib/mirror-sync/data.db"
}
p := os.Getenv("MIRRORSYNC_PORT")
if len(p) == 0 {
p = "25697"
}
port, err := strconv.Atoi(p)
if err != nil {
fmt.Fprintf(os.Stderr, "error: bad MIRRORSYNC_PORT value: %s", err)
os.Exit(1)
}
fmt.Printf("mirror-sync daemon -- v%s.%s.%s\n\n", constants.Version, runtime.GOOS, runtime.GOARCH)
@@ -47,9 +59,9 @@ func main() {
slog.Info("daemon scheduler is running")
// api
s := api.NewServer(data, scheduler, 8080)
s := api.NewServer(data, scheduler, port)
slog.Info("daemon listening to :8080")
slog.Info("daemon listening to :" + p)
if err := s.Server.ListenAndServe(); err != nil {
fmt.Fprintln(os.Stderr, "failed to start server:", err.Error())
os.Exit(1)