Files

57 lines
1.3 KiB
Go
Raw Permalink Normal View History

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"
var bindaddr = flag.String("bind-address", ":8080", "Address to respond to HTTP requests on")
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))
go h.run()
go readInput()
2016-03-10 16:17:47 -08:00
http.HandleFunc("/stream", serveStream)
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:47:04 -08:00
log.Printf("Listening on: %s", *bindaddr)
err := http.ListenAndServe(*bindaddr, nil)
2016-03-10 16:17:47 -08:00
if err != nil {
log.Fatal("Error starting web server: ", err)
2016-03-10 16:17:47 -08:00
}
}