Exit with error code in go?

后端 未结 5 1669
Happy的楠姐
Happy的楠姐 2021-02-01 12:21

What\'s the idiomatic way to exit a program with some error code?

The documentation for Exit says \"The program terminates immediately; deferred functions a

5条回答
  •  生来不讨喜
    2021-02-01 12:55

    In python I commonly use pattern which converted to go looks like this:

    func run() int {
        // here goes
        // the code
    
        return 1
    }
    
    func main() {
        os.Exit(run())
    }
    

提交回复
热议问题