parent
f0ac31fdb1
commit
48f41b8ba1
@ -1,7 +1,49 @@
|
||||
package main
|
||||
|
||||
import "log"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
GitSummary string = "unknown"
|
||||
)
|
||||
|
||||
func actionServ(c *cli.Context) error {
|
||||
fmt.Println("added serv: ", c.Args().First())
|
||||
|
||||
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||
return nil
|
||||
}
|
||||
|
||||
func actionStatus(c *cli.Context) error {
|
||||
log.Println("Status")
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("Started..")
|
||||
app := cli.NewApp()
|
||||
app.Name = "gosuv"
|
||||
app.Version = GitSummary
|
||||
app.Usage = "golang port of python-supervisor"
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "serv",
|
||||
Usage: "Should only called by itself",
|
||||
Action: actionServ,
|
||||
},
|
||||
{
|
||||
Name: "status",
|
||||
Aliases: []string{"st"},
|
||||
Usage: "Show program status",
|
||||
Action: actionStatus,
|
||||
},
|
||||
}
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>gosuv</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hello</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
type Supervisor struct {
|
||||
ConfigDir string
|
||||
}
|
||||
|
||||
func (s *Supervisor) Index(w http.ResponseWriter, r *http.Request) {
|
||||
t := template.Must(template.New("t").ParseFiles("./res/index.html"))
|
||||
t.ExecuteTemplate(w, "index.html", nil)
|
||||
}
|
||||
|
||||
func (s *Supervisor) AddProgram(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
data, _ := json.Marshal(map[string]interface{}{
|
||||
"status": 0,
|
||||
})
|
||||
w.Write(data)
|
||||
}
|
||||
|
||||
func init() {
|
||||
suv := &Supervisor{}
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/", suv.Index)
|
||||
r.HandleFunc("/api/programs", suv.AddProgram).Methods("POST")
|
||||
http.Handle("/", r)
|
||||
}
|
Loading…
Reference in new issue