func main()

in scripts/resolve_i64/main.go [85:164]


func main() {
	thriftFile := os.Args[1]
	idlPathPrefix := os.Args[2]
	annotationJSType := os.Args[3]

	module, err := compile.Compile(thriftFile)
	if err != nil {
		panic(fmt.Sprintf("Failed to parse thrift file: %s", thriftFile))
	}
	meta := &Meta{}

	s := strings.TrimSuffix(thriftFile, ".thrift")
	s = strings.Replace(s, idlPathPrefix, "/build/gen-code/", 1)
	meta.PackageName = filepath.Base(s)

	for _, typeDef := range module.Types {
		t, ok := typeDef.(*compile.TypedefSpec)
		if !ok {
			continue
		}
		i64Struct := I64Struct{}
		if t.Target != nil {
			typThriftAnnotation := t.Target.ThriftAnnotations()
			if typThriftAnnotation != nil {
				p := naivePackageNameResolver{}
				refType, err := codegen.GoReferenceType(&p, t)
				if err != nil {
					fmt.Fprintln(os.Stderr, fmt.Errorf("error parsing reference type: %s", err.Error()))
					os.Exit(1)
					return
				}

				i64Struct.TypedefType = refType[1:]
				if typThriftAnnotation[annotationJSType] == "Long" {
					i64Struct.IsLong = true
				}
				if typThriftAnnotation[annotationJSType] == "Date" {
					i64Struct.IsTimestamp = true
				}
			}
		}
		if i64Struct.IsTimestamp || i64Struct.IsLong {
			meta.Types = append(meta.Types, i64Struct)
		}
	}
	if len(meta.Types) == 0 {
		return
	}
	// Note type defs are not read by unique order so they need to be sorted before writing
	sort.Sort(I64Structs(meta.Types))
	tmpl, err := template.ParseFiles(filepath.Join(getDirName(), templateFileName))
	if err != nil {
		fmt.Fprintln(os.Stderr, fmt.Errorf(
			"error parsing template %s: %s", templateFileName, err.Error()))
		os.Exit(1)
		return
	}
	tplBuffer := bytes.NewBuffer(nil)
	err = tmpl.Execute(tplBuffer, meta)
	if err != nil {
		fmt.Fprintln(os.Stderr, fmt.Errorf(
			"error executing template %s: %s", templateFileName, err.Error()))
		os.Exit(1)
		return
	}
	outName := s + outFileName
	err = ioutil.WriteFile(outName, tplBuffer.Bytes(), 0644)
	if err != nil {
		fmt.Fprintln(os.Stderr, fmt.Errorf(
			"error writing file to %s, err: %s", templateFileName, err.Error()))
		os.Exit(1)
		return
	}

	err = codegen.FormatGoFile(outName)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}