<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/json_array/write.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
commit8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b (patch)
tree7a16883c17c2bdcc49b2f9d4f333dfc76c66248f /json_array/write.go
parent3c34366bdd5d817a184d6b1c901d03a16b6faa4b (diff)
downloadstred-go-8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b.tar
Huge refactor to a more value based system, doing away with terminals. Also introduces unit testing
Diffstat (limited to 'json_array/write.go')
-rw-r--r--json_array/write.go27
1 files changed, 11 insertions, 16 deletions
diff --git a/json_array/write.go b/json_array/write.go
index 4d202c4..aaa2851 100644
--- a/json_array/write.go
+++ b/json_array/write.go
@@ -7,7 +7,7 @@ import (
"encoding/json"
)
-func assembleValue(atoms []walk.Atom) (interface{}, []walk.Atom) {
+func assembleValue(atoms []walk.AtomOLD) (interface{}, []walk.AtomOLD) {
if len(atoms) == 0 {
panic("Missing JSON value in output")
}
@@ -89,21 +89,16 @@ func assembleValue(atoms []walk.Atom) (interface{}, []walk.Atom) {
}
}
-func outputValue(atoms []walk.Atom, writer *bufio.Writer) {
- if len(atoms) == 0 {
- return
- }
- value, atoms := assembleValue(atoms)
- if len(atoms) != 0 {
- panic("Tried to output more than one JSON value")
- }
- bytes, err := json.MarshalIndent(value, "\t", "\t")
- if err != nil {
- panic("Error marshalling json into bytes")
- }
- _, err = writer.Write(bytes)
- if err != nil {
- panic("Error writing value")
+func outputValue(values []interface{}, writer *bufio.Writer) {
+ for _, value := range values {
+ bytes, err := json.MarshalIndent(value, "\t", "\t")
+ if err != nil {
+ panic("Error marshalling json into bytes")
+ }
+ _, err = writer.Write(bytes)
+ if err != nil {
+ panic("Error writing value")
+ }
}
}