This commit is contained in:
alessio 2016-11-13 15:03:19 +01:00
parent 22e5f69a55
commit 90b8d07bae
1 changed files with 4 additions and 10 deletions

View File

@ -3,15 +3,13 @@ package server
import ( import (
"encoding/json" "encoding/json"
"github.com/labstack/echo" "github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/middleware" "github.com/labstack/echo/middleware"
c "github.com/tockins/realize/settings" c "github.com/tockins/realize/settings"
w "github.com/tockins/realize/watcher" w "github.com/tockins/realize/watcher"
"golang.org/x/net/websocket" "golang.org/x/net/websocket"
"log" "gopkg.in/urfave/cli.v2"
"net/http" "net/http"
"strconv" "strconv"
"gopkg.in/urfave/cli.v2"
) )
// Server struct contains server informations // Server struct contains server informations
@ -83,9 +81,9 @@ func (s *Server) Start(p *cli.Context) (err error) {
}) })
//websocket //websocket
e.GET("/ws", standard.WrapHandler(s.projects())) e.GET("/ws", echo.WrapHandler(s.projects()))
go e.Run(standard.New(string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))) go e.Start(string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))
if s.Open || p.Bool("open") { if s.Open || p.Bool("open") {
_, err = Open("http://" + string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port)) _, err = Open("http://" + string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))
if err != nil { if err != nil {
@ -100,12 +98,8 @@ func (s *Server) Start(p *cli.Context) (err error) {
func (s *Server) projects() websocket.Handler { func (s *Server) projects() websocket.Handler {
return websocket.Handler(func(ws *websocket.Conn) { return websocket.Handler(func(ws *websocket.Conn) {
msg := func() { msg := func() {
message, _ := json.Marshal(s.Blueprint.Projects) message, _ := json.Marshal(s.Blueprint.Projects)
err := websocket.Message.Send(ws, string(message)) websocket.Message.Send(ws, string(message))
if err != nil {
log.Fatal(err)
}
} }
msg() msg()
for { for {