1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GolangのPackageとModuleについて

Posted at

GolangのPackageとModuleを使ってGoファイルを分けて関数定義する方法がわからなかったので、調べて実行してみた2022年7月時点の情報を記載します。

Goファイルを作成

次の2つのファイルを作成します。

test1.go
package main

import "fmt"

func main() {
	fmt.Println("test1")
	test2()
}
test2.go
package main

import "fmt"

func test2() {
	fmt.Println("test2")
}

module作成と実行

MacBook-Pro tmp20220722 % go mod init main
go: creating new go.mod: module main
go: to add module requirements and sums:
        go mod tidy
MacBook-Pro tmp20220722 % ls
go.mod          test1.go        test2.go
MacBook-Pro tmp20220722 % go run .
test1
test2

参考

【Go】パッケージ/モジュールやgo modコマンドについてまとめ

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?