itchyny / astgen-go

interface{} => ast.Node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

astgen-go

CI Status Go Report Card MIT License pkg.go.dev

Build Go code from arbitrary value in Go.

Usage

package main

import (
	"go/printer"
	"go/token"
	"log"
	"os"

	"github.com/itchyny/astgen-go"
)

type X struct {
	x int
	y Y
	z *Z
}

type Y struct {
	y int
}

type Z struct {
	s string
	t map[string]int
}

func main() {
	x := &X{1, Y{2}, &Z{"hello", map[string]int{"x": 42}}}
	t, err := astgen.Build(x)
	if err != nil {
		log.Fatal(err)
	}
	err = printer.Fprint(os.Stdout, token.NewFileSet(), t)
	if err != nil {
		log.Fatal(err)
	}
}
&X{x: 1, y: Y{y: 2}, z: &Z{s: "hello", t: map[string]int{"x": 42}}}

Bug Tracker

Report bug at Issues・itchyny/astgen-go - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

About

interface{} => ast.Node

License:MIT License


Languages

Language:Go 98.5%Language:Makefile 1.5%