Skip to content

Commit

Permalink
feat: dump to jsonline by default
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Mar 23, 2024
1 parent 5cebc97 commit c00d3e9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/silo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func run(_ *cobra.Command) error {

defer backend.Close()

writer := silo.NewDumpToStdout()
writer := infra.NewDumpJSONLine()

driver := silo.NewDriver(backend, writer)

Expand Down
56 changes: 56 additions & 0 deletions internal/infra/dump_jsonline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (C) 2023 CGI France
//
// This file is part of SILO.
//
// SILO is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SILO is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SILO. If not, see <http://www.gnu.org/licenses/>.

package infra

import (
"encoding/json"
"fmt"

"github.com/cgi-fr/silo/pkg/silo"
)

type DumpJSONLine struct{}

func NewDumpJSONLine() *DumpJSONLine {
return &DumpJSONLine{}
}

func (d *DumpJSONLine) Write(node silo.DataNode, uuid string) error {
line := struct {
UUID string
ID string
Key any
}{
UUID: uuid,
ID: node.Key,
Key: node.Data,
}

bytes, err := json.Marshal(line)
if err != nil {
return fmt.Errorf("%w", err)
}

println(string(bytes))

return nil
}

func (d *DumpJSONLine) Close() error {
return nil
}

0 comments on commit c00d3e9

Please sign in to comment.