package main

import (
	"flag"
	"fmt"
	"log"
	"net/http"

	"github.com/julienschmidt/httprouter"
	core "gogs.dezendorf.net/breandan/monorepo/dezendorf/applications/golink/internal/core"
	db "gogs.dezendorf.net/breandan/monorepo/dezendorf/applications/golink/internal/database"
	routes "gogs.dezendorf.net/breandan/monorepo/dezendorf/applications/golink/internal/routes"
)

var serverPort = flag.String("port", "80", "webserver port")
var server = flag.Bool("server", false, "enable webserver")

func init() {
	flag.Parse()
}

func main() {
	flag.Parse()
	core.DepImport()
	if *server {
		fmt.Printf("Starting linkserver on port :%s", *serverPort)
		router := httprouter.New()
		router.GET("/", routes.List)
		router.GET("/search/:target", routes.Search)

		if err := http.ListenAndServe(":"+*serverPort, nil); err != nil {
			log.Fatal(err)
		}
	}
}
