mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-03 04:16:03 +02:00
* chore(deps): bump github.com/spf13/viper from 1.16.0 to 1.18.2 Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.16.0 to 1.18.2. - [Release notes](https://github.com/spf13/viper/releases) - [Commits](https://github.com/spf13/viper/compare/v1.16.0...v1.18.2) --- updated-dependencies: - dependency-name: github.com/spf13/viper dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix race --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
48 lines
877 B
Go
48 lines
877 B
Go
package log
|
|
|
|
import (
|
|
"io"
|
|
"slices"
|
|
"sync"
|
|
)
|
|
|
|
// A MultiWriter dispatches writes to multiple writers.
|
|
type MultiWriter struct {
|
|
mu sync.Mutex
|
|
ws []io.Writer
|
|
}
|
|
|
|
// NewMultiWriter creates a new MultiWriter
|
|
func NewMultiWriter() *MultiWriter {
|
|
return &MultiWriter{}
|
|
}
|
|
|
|
// Add adds a writer to the multi writer.
|
|
func (m *MultiWriter) Add(w io.Writer) {
|
|
m.mu.Lock()
|
|
m.ws = append(m.ws, w)
|
|
m.mu.Unlock()
|
|
}
|
|
|
|
// Remove removes a writer from the multi writer.
|
|
func (m *MultiWriter) Remove(w io.Writer) {
|
|
m.mu.Lock()
|
|
m.ws = slices.DeleteFunc(m.ws, func(mw io.Writer) bool {
|
|
return mw == w
|
|
})
|
|
m.mu.Unlock()
|
|
}
|
|
|
|
// Write writes data to all the writers. The last count and error are returned.
|
|
func (m *MultiWriter) Write(data []byte) (int, error) {
|
|
var n int
|
|
var err error
|
|
|
|
m.mu.Lock()
|
|
for _, w := range m.ws {
|
|
n, err = w.Write(data)
|
|
}
|
|
m.mu.Unlock()
|
|
|
|
return n, err
|
|
}
|