diff --git a/func/README.md b/func/README.md new file mode 100644 index 0000000..b478021 --- /dev/null +++ b/func/README.md @@ -0,0 +1,8 @@ +## MEMO + + - 引数をstructや配列をそのまま指定すると値渡し、ポインタを指定すれば参照渡しになる + - 速度を気にするなら参照渡し + - パッケージ分ける場合はgo.modとか使うと便利。`go mod init xxxx/xxx`とかで初期化できる。 + - パッケージでリモートのパスを使う場合`go help importpath`で確認できるようなものが使える(Githubとか) + - replaceを定義しておけばローカルでもリモートでもビルドできる。 + diff --git a/func/func.go b/func/func.go new file mode 100644 index 0000000..438ea78 --- /dev/null +++ b/func/func.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "localhost/hello/sub" +) + +func hello() { + fmt.Println("hello") +} + +func hoge() (int64, int64, int64) { + return 1, 2, 3 +} + +func println(str string) { + fmt.Println(str) +} + +func main() { + hello() + println("println") + sub.Sample() + + v1, v2, v3 := hoge() + fmt.Print(v1, v2, v3) // 1 2 3 + fmt.Println() +} + diff --git a/func/go.mod b/func/go.mod new file mode 100644 index 0000000..ff2c2ef --- /dev/null +++ b/func/go.mod @@ -0,0 +1,5 @@ +module localhost/hello + +go 1.17 + +replace localhost/hello => ./ diff --git a/func/sub/sample.go b/func/sub/sample.go new file mode 100644 index 0000000..b7486d6 --- /dev/null +++ b/func/sub/sample.go @@ -0,0 +1,7 @@ +package sub + +import "fmt" + +func Sample() { + fmt.Println("sample") +}