30 lines
538 B
Go
30 lines
538 B
Go
package config
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
// A method of extracting input from the user.
|
|
type Source interface {
|
|
// Fetch data from this source.
|
|
Extract() (string, error)
|
|
}
|
|
|
|
// A source defined by a string.
|
|
type StringSource struct{ Data string }
|
|
|
|
func (s StringSource) Extract() (string, error) { return s.Data, nil }
|
|
|
|
// A source pulling from standard input.
|
|
type StdinSource struct{}
|
|
|
|
func (s StdinSource) Extract() (string, error) {
|
|
data, err := io.ReadAll(os.Stdin)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(data), nil
|
|
}
|