package main

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

	"git.giaever.org/joachimmg/go-log.git/log"
	"git.giaever.org/joachimmg/m-dns/host"
	"git.giaever.org/joachimmg/m-dns/server"
	"git.giaever.org/joachimmg/m-dns/zone"
)

func init() {
	flag.Parse()
}

func main() {
	hostname, err := os.Hostname()

	if err != nil {
		log.Errorln(err)
	}

	txt := []string{
		"login=true",
		"admin=/admin",
		"autosign=",
	}

	host, err := host.New(
		"This is _a_ .dotted. instance",
		"_myservice._tcp",
		"local",
		hostname,
		[]net.IP{net.ParseIP("192.168.1.128")},
		8080,
		txt,
	)

	if err != nil {
		log.Errorln(err)
	}

	zone, err := zone.New(host)

	if err != nil {
		log.Errorln(err)
	}

	mdnss, err := server.New(zone, nil)

	if err != nil {
		log.Errorln(err)
	}
	log.Traceln(mdnss)

	//mdnss.Daemon()

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, I'm just here hangig around.")
	})

	log.Panicln(http.ListenAndServe(":8080", nil))

}
