package main

import (
	"flag"
	"log"
	"path/filepath"
)

const version = "1"

func main() {
	flag.Parse()

	cfgPath, err := configPath()
	if err != nil {
		log.Fatalf("config path: %v", err)
	}
	logPath, err := setupFileLogging(filepath.Dir(cfgPath))
	if err != nil {
		log.Fatalf("log setup: %v", err)
	}

	log.Printf("datascape-companion %s", version)
	log.Printf("log file: %s", logPath)
	log.Printf("config file: %s", cfgPath)

	cfg, _, err := loadOrInitConfig()
	if err != nil {
		log.Fatalf("config: %v", err)
	}

	srv := newServer(cfg, cfgPath, logPath)
	log.Printf("listening on http://127.0.0.1:%d", cfg.Port)
	log.Printf("settings page: http://127.0.0.1:%d/config", cfg.Port)
	if err := srv.run(); err != nil {
		log.Fatal(err)
	}
}
