1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 14:34:24 +08:00
Files
kubo/core/corehttp/logs.go
Jeromy 90896f283f clean up unused log options
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
2015-06-18 12:44:01 -07:00

46 lines
840 B
Go

package corehttp
import (
"io"
"net/http"
core "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/thirdparty/eventlog"
)
type writeErrNotifier struct {
w io.Writer
errs chan error
}
func newWriteErrNotifier(w io.Writer) (io.Writer, <-chan error) {
ch := make(chan error, 1)
return &writeErrNotifier{
w: w,
errs: ch,
}, ch
}
func (w *writeErrNotifier) Write(b []byte) (int, error) {
n, err := w.w.Write(b)
if err != nil {
select {
case w.errs <- err:
default:
}
}
return n, err
}
func LogOption() ServeOption {
return func(n *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {
mux.HandleFunc("/logs", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
wnf, errs := newWriteErrNotifier(w)
eventlog.WriterGroup.AddWriter(wnf)
<-errs
})
return mux, nil
}
}