update readme

master
codeskyblue 8 years ago
parent 3f64c8e928
commit 554bba9ff1

3
.gitignore vendored

@ -23,4 +23,5 @@ _testmain.go
*.test
*.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)
## Program not implement
**Not done yet.**
golang port of python-supervisor
Process managerment writtern by golang, inspired by python-supervisor
Features
* [ ] Realtime log view
* [x] Realtime log view
* [x] Web control page
* [ ] Github webhook
* [ ] Web control page
* [ ] 中文文档
## Requirements
Go version at least `1.5+`
Go version at least `1.6+`
## Installation
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
go get -d 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
```
## Usage
Start server in the background
```sh
gosuv start-server
```
Show server status
```sh
$ gosuv status
NAME STATUS
timetest running
$ gosuv help
...
Server is running
```
## Configuration
Default config file stored in directory `$HOME/.gosuv/`
## Design
### Get or Update program
HTTP is follow the RESTFul guide.
Get or Update program
`<GET|PUT> /api/programs/:name`
### Add new program
Add new program
`POST /api/programs`
### Del program
Del program
`DELETE /api/programs/:name`
## State

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

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

@ -1,24 +1,3 @@
package main
import "html/template"
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))
}
var templateDir = "res"

@ -83,7 +83,7 @@
</button>
</td>
</tr>
<tr class="success">
<!-- <tr class="success">
<td>gohttpserver</td>
<td>
<span class="status">Running(2h)</span>
@ -102,7 +102,7 @@
<span class="glyphicon glyphicon-cog"></span> Setting
</button>
</td>
</tr>
</tr> -->
</tbody>
</table>
</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"
"errors"
"fmt"
"html/template"
"io/ioutil"
"net/http"
"os"
@ -175,9 +174,11 @@ func (s *Supervisor) saveDB() error {
}
func (s *Supervisor) renderHTML(w http.ResponseWriter, name string, data interface{}) {
baseName := filepath.Base(name)
t := template.Must(template.New("t").Delims("[[", "]]").ParseFiles(name))
t.ExecuteTemplate(w, baseName, data)
executeTemplate(w, name, data)
// baseName := filepath.Base(name)
// t := template.Must(template.New("t").Delims("[[", "]]").ParseFiles(name))
// t.ExecuteTemplate(w, baseName, data)
}
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) {
s.renderHTML(w, "./res/index.html", nil)
s.renderHTML(w, "index", nil)
}
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) {
@ -424,8 +425,8 @@ func registerHTTPHandlers() error {
r.HandleFunc("/ws/events", suv.wsEvents)
r.HandleFunc("/ws/logs/{name}", suv.wsLog)
fs := http.FileServer(http.Dir("res"))
// fs := http.FileServer(http.Dir("res"))
http.Handle("/", r)
http.Handle("/res/", http.StripPrefix("/res/", fs))
// http.Handle("/res/", http.StripPrefix("/res/", fs))
return nil
}

Loading…
Cancel
Save