12345678910111213141516171819202122232425262728293031 |
- package main
- import (
- "fmt"
- "red-green.com/autostruct"
- )
- func main() {
- var a autostruct.AutoStruct
- var err error
- err = a.Init("example", "main", "Example")
- if err != nil {
- fmt.Println(err)
- } else {
- defer a.Close()
- a.PlacePackageName()
- a.Newline()
- a.StartImports()
- a.AddImport("time") // Because we want to use time.Time
- a.EndImports()
- a.Newline()
- a.StartStruct("Person")
- // fieldname, fieldtype, jsontag, comment
- a.AddJsonCommentField("Name", "string", "name", "Person's name")
- a.AddJsonCommentField("Age", "time.Time", "age", "Person's age, saved and loaded as unix")
- a.AddJsonCommentField("Weight", "float32", "weight", "Person's weight in ounces")
- a.AddJsonCommentField("Height", "float32", "height", "Person's height in inches")
- a.EndStruct()
- }
- }
|