Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

flowup/gogen

Repository files navigation

Gogen

Master Status Develop Status Godoc

Warning: This project is under heavy development

Gogen is a library that helps to build Golang code generators with ease. It produces builds from the given .go files or packages. Every build contains useful information about types, functions, methods, constants, etc. This information can be simply used to build templates based on an already existing code.

Gogen directly parses .go files so there is no need of intermediary language. This allows us to simply integrate Gogen into already existing projects.

Example

build := gogen.Parse(BasePathToYourFile)
file := build.File(YourFileName)

// Print all functions
for i, f := range file.Functions() {
  fmt.Println(i,": Structure", f.Name(), "Is method:", f.IsMethod())
}

// Print structures with @dao comment tag
for i, s := range file.Structs().Filter("@dao") {
  fmt.Println(i,": Structure", s.Name(), "Num of fields:", len(s.Fields()))
  for j, field := range s.Fields() {
    ft, _ := field.Type()
    fmt.Println("Field no:", j, "Name:", field.Name(), "Type:", ft)
  }
}

Kickstart

Will be added soon