gofmt

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodeToGo

func NodeToGo(name string, n Node) (string, error)
Example
package main

import (
	"bytes"
	"fmt"
	"github.com/0x51-dev/constructor"
	"github.com/0x51-dev/constructor/fmt/gofmt"
)

func main() {
	raw := `{
	"users": [
		{
			"first_name": "Alice",
			"username": "alice",
			"age": "23"
		},
		{
			"username": "bob",
			"age": 42
		}
	]
}`
	n, err := constructor.Construct(bytes.NewReader([]byte(raw)))
	if err != nil {
		panic(err)
	}
	str, err := gofmt.NodeToGo("Users", n)
	if err != nil {
		panic(err)
	}
	fmt.Println(str)
}
Output:

type Users struct {
	Users []struct {
		Age any /* json.Number, string */ `json:"age"`
		FirstName *string `json:"first_name"`
		Username string `json:"username"`
	} `json:"users"`
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL