Skip to content

christiancadieux2/gostruct2html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gostruct2html

Convert any GO structure to HTML representation using reflection.

Example:

package main
import "fmt"

type Struct1 struct {
	field1 string
	field2 map[string]string
	field3 []string
	field5 Struct3
}

type Struct3 struct {
	subfield1 string
	subfield2 int
}

type Struct2 struct {
	struct1 Struct1
	field4  string
}

var test_struct = Struct2{
	struct1: Struct1{
		field1: "test",
		field2: map[string]string{
			"host_id":     "h.host_id",
			"site_id":     "s.site_id",
			"platform_id": "p.platform_id",
			"agent_id":    "a.agent_id",
			"subnet_id":   "b.subnet_id",
			"master_id":   "e.master_id",
		},
		field3: []string{"this", "is", "a", "test"},
		field5: Struct3{subfield1: "sub1 value", subfield2: 10},
	},
	field4: "This is field4",
}

func main() {
  fmt.Println(Struct2html(test_struct, 10, ""))
}

go run ./*.go > test_struct.html

struct3

About

Convert any Go structure/array/map to html

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published