main.go 792 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "fmt"
  4. "red-green.com/autostruct"
  5. )
  6. func main() {
  7. var a autostruct.AutoStruct
  8. var err error
  9. err = a.Init("example", "main", "Example")
  10. if err != nil {
  11. fmt.Println(err)
  12. } else {
  13. defer a.Close()
  14. a.PlacePackageName()
  15. a.Newline()
  16. a.StartImports()
  17. a.AddImport("time") // Because we want to use time.Time
  18. a.EndImports()
  19. a.Newline()
  20. a.StartStruct("Person")
  21. // fieldname, fieldtype, jsontag, comment
  22. a.AddJsonCommentField("Name", "string", "name", "Person's name")
  23. a.AddJsonCommentField("Age", "time.Time", "age", "Person's age, saved and loaded as unix")
  24. a.AddJsonCommentField("Weight", "float32", "weight", "Person's weight in ounces")
  25. a.AddJsonCommentField("Height", "float32", "height", "Person's height in inches")
  26. a.EndStruct()
  27. }
  28. }