func (pac *Package) GenConst(file string) error { f, err := os.Create(file) if err != nil { return err } defer f.Close() ms, err := gcc.Xml{pac.From.FullPath(), pac.From.GccXmlArgs}.Macros() if err != nil { return err } consts := ms.Constants(pac.From.NamePattern) nm := make(map[string]string) for _, c := range consts { nm[c.Name] = upperName(c.Name, pac.pat) } fp(f, "package ", pac.PacName) fp(f, "") fp(f, "const (") for _, c := range consts { body := c.Body for k, v := range nm { body = replace(body, k, v) } fp(f, upperName(c.Name, pac.pat), "=", body) } fp(f, ")") return nil }
func (pac *Package) GenConst(file string) error { f, err := os.Create(file) if err != nil { return err } defer f.Close() ms, err := gcc.Xml{pac.From.FullPath()}.Macros() if err != nil { return err } consts := ms.Constants(pac.From.NamePrefix) fp(f, "package ", pac.PacName) fp(f, "") fp(f, "const (") for _, c := range consts { fp(f, snakeToCamel(trimPrefix(c.Name, pac.From.NamePrefix)), "=", snakeToCamel(remove(c.Body, pac.From.NamePrefix+"_"))) } fp(f, ")") return nil }