2015-07-17 20:47:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-07-24 20:59:58 +00:00
|
|
|
"log"
|
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 {
|
2015-07-24 20:59:58 +00:00
|
|
|
log.Fatalf("Could not read configuration file: %v", err)
|
2015-07-20 19:45:20 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2015-07-28 21:10:17 +00:00
|
|
|
ResinDataPath = "/mnt/root/resin-data/"
|
2015-07-24 20:59:58 +00:00
|
|
|
listenAddress := 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-28 21:10:17 +00:00
|
|
|
fmt.Println("Going to listen on " + listenAddress)
|
2015-07-24 20:59:58 +00:00
|
|
|
listener, err := net.Listen("unix", listenAddress)
|
2015-07-24 17:26:33 +00:00
|
|
|
if err != nil {
|
2015-07-24 20:59:58 +00:00
|
|
|
log.Fatalf("Could not listen on "+listenAddress+": %v", err)
|
2015-07-24 17:26:33 +00:00
|
|
|
}
|
2015-07-28 21:10:17 +00:00
|
|
|
fmt.Println("Starting HTTP server")
|
2015-07-24 17:26:33 +00:00
|
|
|
err = http.Serve(listener, r)
|
|
|
|
if err != nil {
|
2015-07-24 20:59:58 +00:00
|
|
|
log.Fatalf("Could not start HTTP server: %v", err)
|
2015-07-24 17:26:33 +00:00
|
|
|
}
|
2015-07-17 20:47:26 +00:00
|
|
|
}
|