feat: better structured internal
This commit is contained in:
29
internal/config/source.go
Normal file
29
internal/config/source.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Defines the consumption of different types of input sources.
|
||||
type Source interface {
|
||||
// Get the data.
|
||||
Pull() (string, error)
|
||||
}
|
||||
|
||||
// A source coming from a string.
|
||||
type StringSource struct{ data string }
|
||||
|
||||
func (this StringSource) Pull() (string, error) { return this.data, nil }
|
||||
|
||||
// A source coming from standard input.
|
||||
type StdinSource struct{}
|
||||
|
||||
func (this StdinSource) Pull() (string, error) {
|
||||
data, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
Reference in New Issue
Block a user