Console API: Subscribe to backend.Stdout.

This commit is contained in:
Kleissner
2022-01-06 04:19:20 +01:00
parent adce6fee5c
commit 0bc0d007a4
4 changed files with 10 additions and 3 deletions

5
API.go
View File

@@ -98,6 +98,11 @@ func apiConsole(backend *core.Backend) func(w http.ResponseWriter, r *http.Reque
bufferR := bytes.NewBuffer(make([]byte, 0, 4096))
bufferW := bytes.NewBuffer(make([]byte, 0, 4096))
// subscribe to any output sent to backend.Stdout
subscribeID := backend.Stdout.Subscribe(bufferW)
defer backend.Stdout.Unsubscribe(subscribeID)
// the terminate signal is used to signal the command handler in case the websocket is closed
terminateSignal := make(chan struct{})
defer close(terminateSignal)

View File

@@ -83,6 +83,8 @@ func main() {
os.Exit(status)
}
backend.Stdout.Subscribe(os.Stdout)
apiListen, apiKey, watchPID := parseCmdParams()
startAPI(backend, apiListen, apiKey)

2
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/PeernetOfficial/Cmd
go 1.16
require (
github.com/PeernetOfficial/core v0.0.0-20220103002105-a19bac19163f
github.com/PeernetOfficial/core v0.0.0-20220106031128-5c8b8eb94bd7
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.4.3-0.20210424162022-e8629af678b7
)

4
go.sum
View File

@@ -1,7 +1,7 @@
github.com/IncSW/geoip2 v0.1.1 h1:afzzYF7n9JbdcPy8aiBSgBJuXi4mTWXZ3z6V3o6Vg34=
github.com/IncSW/geoip2 v0.1.1/go.mod h1:adcasR40vXiUBjtzdaTTKL/6wSf+fgO4M8Gve/XzPUk=
github.com/PeernetOfficial/core v0.0.0-20220103002105-a19bac19163f h1:nkMU/dzSA61anIeBJGfCsq1+Ek6VR+BNXi4FnFkVu8k=
github.com/PeernetOfficial/core v0.0.0-20220103002105-a19bac19163f/go.mod h1:VNhfwAZqya5JDZTS/ffa8Shof0OmQCx025CQMieGB7o=
github.com/PeernetOfficial/core v0.0.0-20220106031128-5c8b8eb94bd7 h1:Bb6UCVLSriUYZs5UBO6CtjY98IHAlaGquFSppXmSygE=
github.com/PeernetOfficial/core v0.0.0-20220106031128-5c8b8eb94bd7/go.mod h1:VNhfwAZqya5JDZTS/ffa8Shof0OmQCx025CQMieGB7o=
github.com/akrylysov/pogreb v0.10.1 h1:FqlR8VR7uCbJdfUob916tPM+idpKgeESDXOA1K0DK4w=
github.com/akrylysov/pogreb v0.10.1/go.mod h1:pNs6QmpQ1UlTJKDezuRWmaqkgUE2TuU0YTWyqJZ7+lI=
github.com/enfipy/locker v1.1.0 h1:2zVJ0ky7cS1Vjs0x6OQWFiT2dSEiHrI5/O2KCz1fgGc=