update readme

master
codeskyblue 8 years ago
parent 3f64c8e928
commit 554bba9ff1

3
.gitignore vendored

@ -23,4 +23,5 @@ _testmain.go
*.test *.test
*.prof *.prof
gosuv gosuv
bindata_assetfs.go

@ -2,18 +2,17 @@
[![Build Status](https://travis-ci.org/codeskyblue/gosuv.svg)](https://travis-ci.org/codeskyblue/gosuv) [![Build Status](https://travis-ci.org/codeskyblue/gosuv.svg)](https://travis-ci.org/codeskyblue/gosuv)
## Program not implement ## Program not implement
**Not done yet.** Process managerment writtern by golang, inspired by python-supervisor
golang port of python-supervisor
Features Features
* [ ] Realtime log view * [x] Realtime log view
* [x] Web control page
* [ ] Github webhook * [ ] Github webhook
* [ ] Web control page * [ ] 中文文档
## Requirements ## Requirements
Go version at least `1.5+` Go version at least `1.6+`
## Installation ## Installation
Binary can be download from <https://dl.equinox.io/shengxiang/gosuv/stable> Binary can be download from <https://dl.equinox.io/shengxiang/gosuv/stable>
@ -23,29 +22,47 @@ Or if you have go enviroment, you can also build from source.
```sh ```sh
go get -d github.com/codeskyblue/gosuv go get -d github.com/codeskyblue/gosuv
cd $GOPATH/src/github.com/codeskyblue/gosuv cd $GOPATH/src/github.com/codeskyblue/gosuv
go build
```
If you want to build a standalone binary, run the following command.
```sh
go get github.com/elazarl/go-bindata-assetfs/...
go-bindata-assetfs -tags bindata res/...
go build -tags bindata go build -tags bindata
``` ```
## Usage ## Usage
Start server in the background
```sh
gosuv start-server
```
Show server status
```sh ```sh
$ gosuv status $ gosuv status
NAME STATUS Server is running
timetest running
$ gosuv help
...
``` ```
## Configuration ## Configuration
Default config file stored in directory `$HOME/.gosuv/` Default config file stored in directory `$HOME/.gosuv/`
## Design ## Design
### Get or Update program HTTP is follow the RESTFul guide.
Get or Update program
`<GET|PUT> /api/programs/:name` `<GET|PUT> /api/programs/:name`
### Add new program Add new program
`POST /api/programs` `POST /api/programs`
### Del program Del program
`DELETE /api/programs/:name` `DELETE /api/programs/:name`
## State ## State

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

@ -67,7 +67,7 @@ func actionStartServer(c *cli.Context) error {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} else { } else {
log.Println("Server started") log.Printf("Server started, address %s", addr)
} }
} }
return nil return nil

@ -1,24 +1,3 @@
package main package main
import "html/template" var templateDir = "res"
var (
tmpl *template.Template
templates = map[string]string{
"index": "res/index.html",
"setting": "res/setting.html",
}
)
func ParseTemplate(name string, content string) {
if tmpl == nil {
tmpl = template.New(name)
}
var t *template.Template
if tmpl.Name() == name {
t = tmpl
} else {
t = tmpl.New(name)
}
template.Must(t.New(name).Delims("[[", "]]").Parse(content))
}

@ -83,7 +83,7 @@
</button> </button>
</td> </td>
</tr> </tr>
<tr class="success"> <!-- <tr class="success">
<td>gohttpserver</td> <td>gohttpserver</td>
<td> <td>
<span class="status">Running(2h)</span> <span class="status">Running(2h)</span>
@ -102,7 +102,7 @@
<span class="glyphicon glyphicon-cog"></span> Setting <span class="glyphicon glyphicon-cog"></span> Setting
</button> </button>
</td> </td>
</tr> </tr> -->
</tbody> </tbody>
</table> </table>
</div> </div>

@ -0,0 +1,42 @@
// +build bindata
package main
import (
"html/template"
"io"
"log"
"net/http"
"path/filepath"
)
var tmpl *template.Template
func parseTemplate(name string, content string) {
if tmpl == nil {
tmpl = template.New(name)
}
var t *template.Template
if tmpl.Name() == name {
t = tmpl
} else {
t = tmpl.New(name)
}
template.Must(t.New(name).Delims("[[", "]]").Parse(content))
}
func init() {
http.Handle("/res/", http.StripPrefix("/res/", http.FileServer(assetFS())))
}
func executeTemplate(wr io.Writer, name string, data interface{}) {
if tmpl == nil || tmpl.Lookup(name) == nil {
path := filepath.Join(templateDir, name+".html")
data, err := Asset(path)
if err != nil {
log.Fatal(err)
}
parseTemplate(name, string(data))
}
tmpl.ExecuteTemplate(wr, name, data)
}

@ -0,0 +1,25 @@
// +build !bindata
package main
import (
"html/template"
"io"
"io/ioutil"
"net/http"
"path/filepath"
)
func init() {
fs := http.FileServer(http.Dir(templateDir))
http.Handle("/res/", http.StripPrefix("/res/", fs))
}
func executeTemplate(wr io.Writer, name string, data interface{}) {
path := filepath.Join(templateDir, name+".html")
body, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
template.Must(template.New("t").Delims("[[", "]]").Parse(string(body))).Execute(wr, data)
}

@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"html/template"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
@ -175,9 +174,11 @@ func (s *Supervisor) saveDB() error {
} }
func (s *Supervisor) renderHTML(w http.ResponseWriter, name string, data interface{}) { func (s *Supervisor) renderHTML(w http.ResponseWriter, name string, data interface{}) {
baseName := filepath.Base(name) executeTemplate(w, name, data)
t := template.Must(template.New("t").Delims("[[", "]]").ParseFiles(name)) // baseName := filepath.Base(name)
t.ExecuteTemplate(w, baseName, data)
// t := template.Must(template.New("t").Delims("[[", "]]").ParseFiles(name))
// t.ExecuteTemplate(w, baseName, data)
} }
type JSONResponse struct { type JSONResponse struct {
@ -192,11 +193,11 @@ func (s *Supervisor) renderJSON(w http.ResponseWriter, data JSONResponse) {
} }
func (s *Supervisor) hIndex(w http.ResponseWriter, r *http.Request) { func (s *Supervisor) hIndex(w http.ResponseWriter, r *http.Request) {
s.renderHTML(w, "./res/index.html", nil) s.renderHTML(w, "index", nil)
} }
func (s *Supervisor) hSetting(w http.ResponseWriter, r *http.Request) { func (s *Supervisor) hSetting(w http.ResponseWriter, r *http.Request) {
s.renderHTML(w, "./res/setting.html", nil) s.renderHTML(w, "setting", nil)
} }
func (s *Supervisor) hStatus(w http.ResponseWriter, r *http.Request) { func (s *Supervisor) hStatus(w http.ResponseWriter, r *http.Request) {
@ -424,8 +425,8 @@ func registerHTTPHandlers() error {
r.HandleFunc("/ws/events", suv.wsEvents) r.HandleFunc("/ws/events", suv.wsEvents)
r.HandleFunc("/ws/logs/{name}", suv.wsLog) r.HandleFunc("/ws/logs/{name}", suv.wsLog)
fs := http.FileServer(http.Dir("res")) // fs := http.FileServer(http.Dir("res"))
http.Handle("/", r) http.Handle("/", r)
http.Handle("/res/", http.StripPrefix("/res/", fs)) // http.Handle("/res/", http.StripPrefix("/res/", fs))
return nil return nil
} }

Loading…
Cancel
Save