Defer



fn read_log() { f := os.open('log.txt') defer { f.close() } ... if !ok { // defer statement will be called here, the file will be closed return } ... // defer statement will be called here, the file will be closed }