30 lines
531 B
Go
30 lines
531 B
Go
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 (s StringSource) Pull() (string, error) { return s.data, nil }
|
|
|
|
// A source coming from standard input.
|
|
type StdinSource struct{}
|
|
|
|
func (s StdinSource) Pull() (string, error) {
|
|
data, err := io.ReadAll(os.Stdin)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(data), nil
|
|
}
|