example.go 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "net"
  6. "net/http"
  7. "os"
  8. "git.giaever.org/joachimmg/go-log.git/log"
  9. "git.giaever.org/joachimmg/m-dns/host"
  10. "git.giaever.org/joachimmg/m-dns/server"
  11. "git.giaever.org/joachimmg/m-dns/zone"
  12. )
  13. func init() {
  14. flag.Parse()
  15. }
  16. func main() {
  17. hostname, err := os.Hostname()
  18. if err != nil {
  19. log.Errorln(err)
  20. }
  21. txt := []string{
  22. "login=true",
  23. "admin=/admin",
  24. "autosign=",
  25. }
  26. host, err := host.New(
  27. "This is _a_ .dotted. instance",
  28. "_myservice._tcp",
  29. "local",
  30. hostname,
  31. []net.IP{net.ParseIP("192.168.1.128")},
  32. 8080,
  33. txt,
  34. )
  35. if err != nil {
  36. log.Errorln(err)
  37. }
  38. zone, err := zone.New(host)
  39. if err != nil {
  40. log.Errorln(err)
  41. }
  42. mdnss, err := server.New(zone, nil)
  43. if err != nil {
  44. log.Errorln(err)
  45. }
  46. log.Traceln(mdnss)
  47. //mdnss.Daemon()
  48. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  49. fmt.Fprintf(w, "Hello, I'm just here hangig around.")
  50. })
  51. log.Panicln(http.ListenAndServe(":8080", nil))
  52. }