mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-06 02:13:17 -06:00
messing about with decoding/encoding
This commit is contained in:
parent
2ec36349c7
commit
3641d47e7e
22 changed files with 2276 additions and 32 deletions
|
|
@ -19,7 +19,6 @@
|
|||
package trans
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
|
@ -35,26 +34,25 @@ func (e *exporter) ExportMinimal(ctx context.Context, path string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
w := bufio.NewWriter(f)
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder := json.NewEncoder(f)
|
||||
|
||||
accounts := []*transmodel.Account{}
|
||||
if err := e.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: nil}}, &accounts); err != nil {
|
||||
return fmt.Errorf("error selecting accounts: %s", err)
|
||||
return fmt.Errorf("ExportMinimal: error selecting accounts: %s", err)
|
||||
}
|
||||
|
||||
for _, a := range accounts {
|
||||
encoder.Encode(a)
|
||||
a.Type = transmodel.TransAccount
|
||||
if err := encoder.Encode(a); err != nil {
|
||||
return fmt.Errorf("ExportMinimal: error encoding account: %s", err)
|
||||
}
|
||||
e.log.Infof("ExportMinimal: exported account %s to %s", a.ID, path)
|
||||
}
|
||||
|
||||
return neatClose(w, f)
|
||||
return neatClose(f)
|
||||
}
|
||||
|
||||
func neatClose(w *bufio.Writer, f *os.File) error {
|
||||
if err := w.Flush(); err != nil {
|
||||
return fmt.Errorf("error flushing writer: %s", err)
|
||||
}
|
||||
|
||||
func neatClose(f *os.File) error {
|
||||
if err := f.Close(); err != nil {
|
||||
return fmt.Errorf("error closing file: %s", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue