var list … var write … var rewriteRule … var simplifyAST … var doDiff … var allErrors … var cpuprofile … const tabWidth … const printerMode … const printerNormalizeNumbers … var fdSem … var rewrite … var parserMode … func usage() { … } func initParserMode() { … } func isGoFile(f fs.DirEntry) bool { … } type sequencer … // newSequencer returns a sequencer that allows concurrent tasks up to maxWeight // and writes tasks' output to out and err. func newSequencer(maxWeight int64, out, err io.Writer) *sequencer { … } const exclusive … // Add blocks until the sequencer has enough weight to spare, then adds f as a // task to be executed concurrently. // // If the weight is either negative or larger than the sequencer's maximum // weight, Add blocks until all other tasks have completed, then the task // executes exclusively (blocking all other calls to Add until it completes). // // f may run concurrently in a goroutine, but its output to the passed-in // reporter will be sequential relative to the other tasks in the sequencer. // // If f invokes a method on the reporter, execution of that method may block // until the previous task has finished. (To maximize concurrency, f should // avoid invoking the reporter until it has finished any parallelizable work.) // // If f returns a non-nil error, that error will be reported after f's output // (if any) and will cause a nonzero final exit code. func (s *sequencer) Add(weight int64, f func(*reporter) error) { … } // AddReport prints an error to s after the output of any previously-added // tasks, causing the final exit code to be nonzero. func (s *sequencer) AddReport(err error) { … } // GetExitCode waits for all previously-added tasks to complete, then returns an // exit code for the sequence suitable for passing to os.Exit. func (s *sequencer) GetExitCode() int { … } type reporter … type reporterState … // getState blocks until any prior reporters are finished with the reporter // state, then returns the state for manipulation. func (r *reporter) getState() *reporterState { … } // Warnf emits a warning message to the reporter's error stream, // without changing its exit code. func (r *reporter) Warnf(format string, args ...any) { … } // Write emits a slice to the reporter's output stream. // // Any error is returned to the caller, and does not otherwise affect the // reporter's exit code. func (r *reporter) Write(p []byte) (int, error) { … } // Report emits a non-nil error to the reporter's error stream, // changing its exit code to a nonzero value. func (r *reporter) Report(err error) { … } func (r *reporter) ExitCode() int { … } // If info == nil, we are formatting stdin instead of a file. // If in == nil, the source is the contents of the file with the given filename. func processFile(filename string, info fs.FileInfo, in io.Reader, r *reporter) error { … } // readFile reads the contents of filename, described by info. // If in is non-nil, readFile reads directly from it. // Otherwise, readFile opens and reads the file itself, // with the number of concurrently-open files limited by fdSem. func readFile(filename string, info fs.FileInfo, in io.Reader) ([]byte, error) { … } func main() { … } func gofmtMain(s *sequencer) { … } func fileWeight(path string, info fs.FileInfo) int64 { … } // writeFile updates a file with the new formatted data. func writeFile(filename string, orig, formatted []byte, perm fs.FileMode, size int64) error { … } // backupFile writes data to a new file named filename<number> with permissions perm, // with <number> randomly chosen such that the file name is unique. backupFile returns // the chosen file name. func backupFile(filename string, data []byte, perm fs.FileMode) (string, error) { … }