Added -o flag to write results to files using a new Destination interface. Changes: - Add Destination interface with StdoutDestination and FileDestination implementations. - Add -o flag to CLI parser for output file specification. - Update Config to use Destination instead of direct output handling. - Refactor main to use Destination.Write() for result output.
28 lines
523 B
Go
28 lines
523 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// A method of writing output to the user.
|
|
type Destination interface {
|
|
// Write data to this destination.
|
|
Write(data string) error
|
|
}
|
|
|
|
// A destination writing to stdout.
|
|
type StdoutDestination struct{}
|
|
|
|
func (d StdoutDestination) Write(data string) error {
|
|
fmt.Println(data)
|
|
return nil
|
|
}
|
|
|
|
// A destination writing to a file.
|
|
type FileDestination struct{ Path string }
|
|
|
|
func (d FileDestination) Write(data string) error {
|
|
return os.WriteFile(d.Path, []byte(data+"\n"), 0644)
|
|
}
|