User custom websocket writter
This commit is contained in:
parent
2ba2a4ba19
commit
7656ca80c5
|
@ -1,7 +1,7 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"magmise/models"
|
||||
"net/http"
|
||||
|
@ -44,17 +44,19 @@ func (c Container) Stop(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (c Container) Logs(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
name := chi.URLParam(r, "name")
|
||||
if name == "" {
|
||||
http.Error(w, "Missing container name", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
log.Println("Logs ", name)
|
||||
id, err := models.GetId(name)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
ws, err := upgrader.Upgrade(w, r, nil)
|
||||
ws, err := Websocket(w, r)
|
||||
if err != nil {
|
||||
log.Print("upgrade:", err)
|
||||
return
|
||||
|
@ -65,10 +67,7 @@ func (c Container) Logs(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
for {
|
||||
defer logs.Close()
|
||||
io.Copy(ws, logs)
|
||||
|
||||
buf.ReadFrom(logs)
|
||||
ws.WriteMessage(0, buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue