01_hello / func /
yhornisse authored on 27 Sep 2021
..
sub add func and package sample 2 years ago
README.md add bare return sample 2 years ago
bareReturn.go add bare return sample 2 years ago
defer.go add sample 2 years ago
func.go add sample code 2 years ago
go.mod add func and package sample 2 years ago
loop.go add sample 2 years ago
vargs.go add sample 2 years ago
README.md

MEMO

  • 戻り値は複数定義できる。エラー通知や成功失敗などにはこれが使える。
  • 返却値を捨てる場合は _ を指定する。
  • 引数をstructや配列をそのまま指定すると値渡し、ポインタを指定すれば参照渡しになる
    • 速度を気にするなら参照渡し
  • パッケージ分ける場合はgo.modとか使うと便利。go mod init xxxx/xxxとかで初期化できる。
    • パッケージでリモートのパスを使う場合go help importpathで確認できるようなものが使える(Githubとか)
    • replaceを定義しておけばローカルでもリモートでもビルドできる。
  • 違うパッケージからアクセスするには大文字始まりの名前にする必要がある。
  • 空returnを使うと効率的な場合があるが、返却値が明示的でない場合があるので控えめに使う方が良いとのこと( bareReturn.goを参照 )