-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-60: DataSink, DataSource, BorrowedSample. Better core docs
- Loading branch information
Showing
13 changed files
with
433 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2018 Yandex LLC. All rights reserved. | ||
// Use of this source code is governed by a MPL 2.0 | ||
// license that can be found in the LICENSE file. | ||
// Author: Vladimir Skipor <skipor@yandex-team.ru> | ||
|
||
package coreutil | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/yandex/pandora/core" | ||
) | ||
|
||
type DataSinkFunc func() (wc io.WriteCloser, err error) | ||
|
||
func (f DataSinkFunc) OpenSink() (wc io.WriteCloser, err error) { | ||
return f() | ||
} | ||
|
||
var _ core.DataSink = DataSinkFunc(nil) | ||
|
||
type DataSourceFunc func() (wc io.ReadCloser, err error) | ||
|
||
func (f DataSourceFunc) OpenSource() (rc io.ReadCloser, err error) { | ||
return f() | ||
} | ||
|
||
var _ core.DataSource = DataSourceFunc(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2018 Yandex LLC. All rights reserved. | ||
// Use of this source code is governed by a MPL 2.0 | ||
// license that can be found in the LICENSE file. | ||
// Author: Vladimir Skipor <skipor@yandex-team.ru> | ||
|
||
package coreutil | ||
|
||
import "github.com/yandex/pandora/core" | ||
|
||
func ReturnSampleIfBorrowed(s core.Sample) { | ||
borrowed, ok := s.(core.BorrowedSample) | ||
if !ok { | ||
return | ||
} | ||
borrowed.Return() | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2018 Yandex LLC. All rights reserved. | ||
// Use of this source code is governed by a MPL 2.0 | ||
// license that can be found in the LICENSE file. | ||
// Author: Vladimir Skipor <skipor@yandex-team.ru> | ||
|
||
package datasink | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/afero" | ||
|
||
"github.com/yandex/pandora/core" | ||
) | ||
|
||
type FileSinkConfig struct { | ||
Path string | ||
} | ||
|
||
func NewFileSink(fs afero.Fs, conf FileSinkConfig) core.DataSink { | ||
return &fileSink{afero.Afero{fs}, conf} | ||
} | ||
|
||
type fileSink struct { | ||
fs afero.Afero | ||
conf FileSinkConfig | ||
} | ||
|
||
func (s *fileSink) OpenSink() (wc io.WriteCloser, err error) { | ||
return s.fs.OpenFile(s.conf.Path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) | ||
} | ||
|
||
func NewStdoutSink() core.DataSink { | ||
return hideCloseFileSink{os.Stdout} | ||
} | ||
|
||
func NewStderrSink() core.DataSink { | ||
return hideCloseFileSink{os.Stderr} | ||
} | ||
|
||
type hideCloseFileSink struct{ *os.File } | ||
|
||
func (f hideCloseFileSink) OpenSink() (wc io.WriteCloser, err error) { | ||
return f, nil | ||
} | ||
|
||
func (f hideCloseFileSink) Close() error { return nil } |
Oops, something went wrong.