2015-07-17 20:47:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-07-24 17:26:33 +00:00
|
|
|
"net"
|
2015-07-17 20:47:26 +00:00
|
|
|
"net/http"
|
2015-07-24 17:26:33 +00:00
|
|
|
"os"
|
2015-07-17 20:47:26 +00:00
|
|
|
|
|
|
|
"resin-supervisor/Godeps/_workspace/src/github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
2015-07-20 19:45:20 +00:00
|
|
|
func pingHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintln(w, "OK")
|
2015-07-17 20:47:26 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 19:45:20 +00:00
|
|
|
//var Config UserConfig // Disabled until we use Config
|
|
|
|
var ResinDataPath string
|
|
|
|
|
2015-07-17 20:47:26 +00:00
|
|
|
func main() {
|
2015-07-20 19:45:20 +00:00
|
|
|
fmt.Println("Resin Go Supervisor starting")
|
|
|
|
/* Disabled until we use Config
|
|
|
|
var err error
|
|
|
|
Config, err = ReadConfig("/boot/config.json")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
ResinDataPath = "/resin-data/"
|
2015-07-24 17:26:33 +00:00
|
|
|
laddr := os.Getenv("GOSUPER_SOCKET")
|
2015-07-20 19:45:20 +00:00
|
|
|
|
2015-07-17 20:47:26 +00:00
|
|
|
r := mux.NewRouter()
|
2015-07-20 19:45:20 +00:00
|
|
|
r.HandleFunc("/ping", pingHandler)
|
|
|
|
apiv1 := r.PathPrefix("/v1").Subrouter()
|
|
|
|
|
|
|
|
apiv1.HandleFunc("/purge", PurgeHandler).Methods("POST")
|
|
|
|
|
2015-07-24 17:26:33 +00:00
|
|
|
listener, err := net.Listen("unix", laddr)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Could not listen on " + laddr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = http.Serve(listener, r)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Could not start HTTP server")
|
|
|
|
return
|
|
|
|
}
|
2015-07-17 20:47:26 +00:00
|
|
|
}
|