Esempio n. 1
0
// Parse construct *BuildSource from package & type information.
func Parse(pkg *genbase.PackageInfo, typeInfos genbase.TypeInfos) (*BuildSource, error) {
	bu := &BuildSource{
		g:         genbase.NewGenerator(pkg),
		pkg:       pkg,
		typeInfos: typeInfos,
	}

	bu.g.AddImport("golang.org/x/net/context", "")
	bu.g.AddImport("google.golang.org/appengine/search", "")
	bu.g.AddImport("google.golang.org/appengine/log", "")
	bu.g.AddImport("bytes", "")
	bu.g.AddImport("github.com/favclip/smg/smgutils", "")
	bu.g.AddImport("errors", "")
	bu.g.AddImport("time", "")

	for _, typeInfo := range typeInfos {
		err := bu.parseStruct(typeInfo)
		if err != nil {
			return nil, err
		}
	}

	for _, st := range bu.Structs {
		if st.HasJSON() {
			bu.g.AddImport("encoding/json", "")
		}
		if id := st.ID(); id != nil && (id.fieldInfo.IsInt() || id.fieldInfo.IsInt64()) {
			bu.g.AddImport("strconv", "")
		}
		if st.HasString() {
			bu.g.AddImport("strconv", "")
		}
		if st.HasUnixTime() {
			bu.g.AddImport("time", "")
		}
		for _, field := range st.Fields {
			if field.fieldInfo.IsTime() {
				bu.g.AddImport("time", "")
			}
		}
	}

	return bu, nil
}
Esempio n. 2
0
// Parse construct *BuildSource from package & type information.
func Parse(pkg *genbase.PackageInfo, typeInfos genbase.TypeInfos) (*BuildSource, error) {
	bu := &BuildSource{
		g:         genbase.NewGenerator(pkg),
		pkg:       pkg,
		typeInfos: typeInfos,
	}

	bu.g.AddImport("google.golang.org/appengine/datastore", "")
	bu.g.AddImport("github.com/favclip/qbg/qbgutils", "")

	for _, typeInfo := range typeInfos {
		err := bu.parseStruct(typeInfo)
		if err != nil {
			return nil, err
		}
	}

	return bu, nil
}