@kjk1/

gobook defer basics

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.21848988728392205","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgImZtdCIKCi8vIDpzaG93IHN0YXJ0CmZ1bmMgbG9nRXhpdChuYW1lIHN0cmluZykgewoJZm10LlByaW50ZigiRnVuY3Rpb24gJXMgcmV0dXJuZWRcbiIsIG5hbWUpCn0KCmZ1bmMgbWFpbigpIHsKCWZtdC5QcmludGxuKCJGaXJzdCBtYWluIHN0YXRlbWVudCIpCglkZWZlciBsb2dFeGl0KCJtYWluIikgLy8gcG9zaXRpb24gb2YgZGVmZXIgc3RhdGVtZW50IGhlcmUgZG9lcyBub3QgbWF0dGVyCglmbXQuUHJpbnRsbigiTGFzdCBtYWluIHN0YXRlbWVudCIpCn0KCi8vIDpzaG93IGVuZA=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package main

import "fmt"

// :show start
func logExit(name string) {
	fmt.Printf("Function %s returned\n", name)
}

func main() {
	fmt.Println("First main statement")
	defer logExit("main") // position of defer statement here does not matter
	fmt.Println("Last main statement")
}

// :show end