assets:dashboard static resources

This commit is contained in:
panhao
2016-08-09 21:17:02 +08:00
parent 1da81ad7d3
commit d813b953dd
13 changed files with 732 additions and 0 deletions

View File

@@ -16,10 +16,23 @@ package server
import (
"fmt"
"frp/models/metric"
"html/template"
"net/http"
"github.com/gin-gonic/gin"
)
func index(w http.ResponseWriter, r *http.Request) {
serinfo := metric.GetAllProxyMetrics()
t := template.Must(template.New("index.html").Delims("<<<", ">>>").ParseFiles("index.html"))
err := t.Execute(w, serinfo)
if err != nil {
fmt.Println(err.Error())
}
}
func RunDashboardServer(addr string, port int64) (err error) {
defer func() {
if r := recover(); r != nil {
@@ -34,3 +47,24 @@ func RunDashboardServer(addr string, port int64) (err error) {
go router.Run(fmt.Sprintf("%s:%d", addr, port))
return
}
func RunDashboardServer2(addr string, port int64) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%v", r)
}
}()
http.HandleFunc("/", index)
fs := http.FileServer(http.Dir("static"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
newPort := fmt.Sprintf(":%d", port)
err = http.ListenAndServe(newPort, nil)
if err != nil {
return err
}
return nil
}