Skip to content

Commit 55913bb

Browse files
fix: go multiline
1 parent dcb25c3 commit 55913bb

File tree

1 file changed

+106
-108
lines changed

1 file changed

+106
-108
lines changed

packages/quicktype-core/src/language/Golang/GolangRenderer.ts

Lines changed: 106 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -489,117 +489,115 @@ export class GoRenderer extends ConvenienceRenderer {
489489
this.emitPackageDefinitons(true, imports);
490490
this.ensureBlankLine();
491491
this.emitMultiline(`func unmarshalUnion(data []byte, pi **int64, pf **float64, pb **bool, ps **string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) (bool, error) {
492-
if pi != nil {
493-
*pi = nil
494-
}
495-
if pf != nil {
496-
*pf = nil
497-
}
498-
if pb != nil {
499-
*pb = nil
500-
}
501-
if ps != nil {
502-
*ps = nil
503-
}
504-
505-
dec := json.NewDecoder(bytes.NewReader(data))
506-
dec.UseNumber()
507-
tok, err := dec.Token()
508-
if err != nil {
509-
return false, err
510-
}
511-
512-
switch v := tok.(type) {
513-
case json.Number:
514-
if pi != nil {
515-
i, err := v.Int64()
516-
if err == nil {
517-
*pi = &i
518-
return false, nil
519-
}
520-
}
521-
if pf != nil {
522-
f, err := v.Float64()
523-
if err == nil {
524-
*pf = &f
525-
return false, nil
526-
}
527-
return false, errors.New("Unparsable number")
528-
}
529-
return false, errors.New("Union does not contain number")
530-
case float64:
531-
return false, errors.New("Decoder should not return float64")
532-
case bool:
533-
if pb != nil {
534-
*pb = &v
535-
return false, nil
536-
}
537-
return false, errors.New("Union does not contain bool")
538-
case string:
539-
if haveEnum {
540-
return false, json.Unmarshal(data, pe)
541-
}
542-
if ps != nil {
543-
*ps = &v
544-
return false, nil
545-
}
546-
return false, errors.New("Union does not contain string")
547-
case nil:
548-
if nullable {
549-
return false, nil
550-
}
551-
return false, errors.New("Union does not contain null")
552-
case json.Delim:
553-
if v == '{' {
554-
if haveObject {
555-
return true, json.Unmarshal(data, pc)
556-
}
557-
if haveMap {
558-
return false, json.Unmarshal(data, pm)
559-
}
560-
return false, errors.New("Union does not contain object")
561-
}
562-
if v == '[' {
563-
if haveArray {
564-
return false, json.Unmarshal(data, pa)
565-
}
566-
return false, errors.New("Union does not contain array")
567-
}
568-
return false, errors.New("Cannot handle delimiter")
569-
}
570-
return false, errors.New("Cannot unmarshal union")
571-
492+
if pi != nil {
493+
*pi = nil
494+
}
495+
if pf != nil {
496+
*pf = nil
497+
}
498+
if pb != nil {
499+
*pb = nil
500+
}
501+
if ps != nil {
502+
*ps = nil
503+
}
504+
dec := json.NewDecoder(bytes.NewReader(data))
505+
dec.UseNumber()
506+
tok, err := dec.Token()
507+
if err != nil {
508+
return false, err
509+
}
510+
switch v := tok.(type) {
511+
case json.Number:
512+
if pi != nil {
513+
i, err := v.Int64()
514+
if err == nil {
515+
*pi = &i
516+
return false, nil
517+
}
518+
}
519+
if pf != nil {
520+
f, err := v.Float64()
521+
if err == nil {
522+
*pf = &f
523+
return false, nil
524+
}
525+
return false, errors.New("Unparsable number")
526+
}
527+
return false, errors.New("Union does not contain number")
528+
case float64:
529+
return false, errors.New("Decoder should not return float64")
530+
case bool:
531+
if pb != nil {
532+
*pb = &v
533+
return false, nil
534+
}
535+
return false, errors.New("Union does not contain bool")
536+
case string:
537+
if haveEnum {
538+
return false, json.Unmarshal(data, pe)
539+
}
540+
if ps != nil {
541+
*ps = &v
542+
return false, nil
543+
}
544+
return false, errors.New("Union does not contain string")
545+
case nil:
546+
if nullable {
547+
return false, nil
548+
}
549+
return false, errors.New("Union does not contain null")
550+
case json.Delim:
551+
if v == '{' {
552+
if haveObject {
553+
return true, json.Unmarshal(data, pc)
554+
}
555+
if haveMap {
556+
return false, json.Unmarshal(data, pm)
557+
}
558+
return false, errors.New("Union does not contain object")
559+
}
560+
if v == '[' {
561+
if haveArray {
562+
return false, json.Unmarshal(data, pa)
563+
}
564+
return false, errors.New("Union does not contain array")
565+
}
566+
return false, errors.New("Cannot handle delimiter")
567+
}
568+
return false, errors.New("Cannot unmarshal union")
572569
}
573570
574571
func marshalUnion(pi *int64, pf *float64, pb *bool, ps *string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) ([]byte, error) {
575-
if pi != nil {
576-
return json.Marshal(*pi)
577-
}
578-
if pf != nil {
579-
return json.Marshal(*pf)
580-
}
581-
if pb != nil {
582-
return json.Marshal(*pb)
583-
}
584-
if ps != nil {
585-
return json.Marshal(*ps)
586-
}
587-
if haveArray {
588-
return json.Marshal(pa)
589-
}
590-
if haveObject {
591-
return json.Marshal(pc)
592-
}
593-
if haveMap {
594-
return json.Marshal(pm)
595-
}
596-
if haveEnum {
597-
return json.Marshal(pe)
598-
}
599-
if nullable {
600-
return json.Marshal(nil)
601-
}
602-
return nil, errors.New("Union must not be null")
572+
{
573+
if pi != nil {
574+
return json.Marshal(*pi)
575+
}
576+
if pf != nil {
577+
return json.Marshal(*pf)
578+
}
579+
if pb != nil {
580+
return json.Marshal(*pb)
581+
}
582+
if ps != nil {
583+
return json.Marshal(*ps)
584+
}
585+
if haveArray {
586+
return json.Marshal(pa)
587+
}
588+
if haveObject {
589+
return json.Marshal(pc)
590+
}
591+
if haveMap {
592+
return json.Marshal(pm)
593+
}
594+
if haveEnum {
595+
return json.Marshal(pe)
596+
}
597+
if nullable {
598+
return json.Marshal(nil)
599+
}
600+
return nil, errors.New("Union must not be null")
603601
}`);
604602
this.endFile();
605603
}

0 commit comments

Comments
 (0)