main.go 712 B

123456789101112131415161718192021222324252627282930
  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")
  18. a.EndImports()
  19. a.Newline()
  20. a.StartStruct("Person")
  21. a.AddJsonCommentField("Name", "string", "name", "Person's name")
  22. a.AddJsonCommentField("Age", "time.Time", "age", "Person's age, saved and loaded as unix")
  23. a.AddJsonCommentField("Weight", "float32", "weight", "Person's weight in ounces")
  24. a.AddJsonCommentField("Height", "float32", "height", "Person's height in inches")
  25. a.EndStruct()
  26. }
  27. }