2016-03-10 16:17:47 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"flag"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
2016-03-10 22:15:22 -08:00
|
|
|
"os"
|
|
|
|
|
"runtime"
|
2016-03-10 16:17:47 -08:00
|
|
|
)
|
|
|
|
|
|
2016-03-10 22:15:22 -08:00
|
|
|
// #cgo LDFLAGS: -lcap
|
|
|
|
|
// #include <assert.h>
|
|
|
|
|
// #include <stdlib.h>
|
|
|
|
|
// #include <sys/capability.h>
|
|
|
|
|
// const char *get_caps_str() {
|
|
|
|
|
// cap_t caps = cap_get_proc();
|
|
|
|
|
// assert(caps);
|
|
|
|
|
// char *caps_str = cap_to_text(caps, NULL);
|
|
|
|
|
// assert(caps_str);
|
|
|
|
|
// assert(!cap_free(caps));
|
|
|
|
|
// return caps_str;
|
|
|
|
|
// }
|
|
|
|
|
import "C"
|
|
|
|
|
|
2016-03-10 20:19:29 -08:00
|
|
|
var bindaddr = flag.String("bind-address", ":8080", "Address to respond to HTTP requests on")
|
2016-03-10 21:44:00 -08:00
|
|
|
var staticdir = flag.String("static-dir", "", "Static directory to serve at /")
|
2016-03-10 16:17:47 -08:00
|
|
|
|
|
|
|
|
func main() {
|
2016-03-10 17:54:32 -08:00
|
|
|
log.SetFlags(0)
|
2016-03-10 21:47:04 -08:00
|
|
|
log.SetPrefix("{adsb-ws} ")
|
2016-03-10 16:17:47 -08:00
|
|
|
flag.Parse()
|
2016-03-10 22:15:22 -08:00
|
|
|
|
|
|
|
|
caps_str := C.get_caps_str()
|
|
|
|
|
log.Printf("Runtime data:")
|
|
|
|
|
log.Printf("\tgo_version: %s", runtime.Version())
|
|
|
|
|
log.Printf("\tgo_compiler: %s", runtime.Compiler)
|
|
|
|
|
log.Printf("\tgo_arch: %s", runtime.GOARCH)
|
|
|
|
|
log.Printf("\tgo_os: %s", runtime.GOOS)
|
|
|
|
|
log.Printf("\tprocess_id: %d", os.Getpid())
|
|
|
|
|
log.Printf("\tcapabilities: %s", C.GoString(caps_str))
|
|
|
|
|
|
2016-03-10 20:19:29 -08:00
|
|
|
go h.run()
|
2016-03-10 17:07:44 -08:00
|
|
|
go readInput()
|
2016-03-10 21:44:00 -08:00
|
|
|
|
2016-03-10 16:17:47 -08:00
|
|
|
http.HandleFunc("/stream", serveStream)
|
2016-03-10 21:44:00 -08:00
|
|
|
if *staticdir != "" {
|
|
|
|
|
fs := http.FileServer(http.Dir(*staticdir))
|
|
|
|
|
http.Handle("/", fs)
|
2016-03-10 21:47:04 -08:00
|
|
|
log.Printf("Serving static content from: %s", *staticdir)
|
2016-03-10 21:44:00 -08:00
|
|
|
}
|
2016-03-10 21:47:04 -08:00
|
|
|
log.Printf("Listening on: %s", *bindaddr)
|
2016-03-10 20:19:29 -08:00
|
|
|
err := http.ListenAndServe(*bindaddr, nil)
|
2016-03-10 16:17:47 -08:00
|
|
|
if err != nil {
|
2016-03-10 20:19:29 -08:00
|
|
|
log.Fatal("Error starting web server: ", err)
|
2016-03-10 16:17:47 -08:00
|
|
|
}
|
|
|
|
|
}
|