isolate record reading and writing from processing
All checks were successful
Tests / tests (pull_request) Successful in 17s
All checks were successful
Tests / tests (pull_request) Successful in 17s
This commit is contained in:
31
internal/stdout.go
Normal file
31
internal/stdout.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ReportLogger struct {
|
||||
counter int
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
func NewStdOutLogger() *ReportLogger {
|
||||
return &ReportLogger{
|
||||
writer: os.Stdout,
|
||||
}
|
||||
}
|
||||
|
||||
func NewReportLogger(w io.Writer) *ReportLogger {
|
||||
return &ReportLogger{
|
||||
writer: w,
|
||||
}
|
||||
}
|
||||
|
||||
func (rl *ReportLogger) Write(ri ReportItem) error {
|
||||
rl.counter++
|
||||
_, err := fmt.Fprintf(rl.writer, "%6d - realised %+f on %s\n", rl.counter, ri.RealisedPnL(), ri.SellTimestamp.Format(time.RFC3339))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user