Implemented the initial Go framework
This commit is contained in:
39
internal/builtin/output.go
Normal file
39
internal/builtin/output.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/model"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
||||
)
|
||||
|
||||
type jsonOutputWriter struct{}
|
||||
|
||||
func (jsonOutputWriter) Name() string {
|
||||
return "json"
|
||||
}
|
||||
|
||||
func (jsonOutputWriter) Write(ctx context.Context, out model.FinalTranscript, rpt report.Report, cfg config.Config) ([]report.Event, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file, err := os.Create(cfg.OutputFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
enc := json.NewEncoder(file)
|
||||
enc.SetIndent("", " ")
|
||||
if err := enc.Encode(out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return []report.Event{
|
||||
report.Info("output", "json", "wrote placeholder transcript JSON"),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user