0
0

More than 1 year has passed since last update.

Go言語の英語チュートリアル ペライチ Hello world go version go1.18.3 windows

Last updated at Posted at 2022-06-27

大学でCのTAをやって以来ですが、Go言語を勉強してみます。

チュートリアルの概要

Windowsで、cmdとVSCode(要ダウンロード)を使いました。
Go version : go1.18.3 windows/amd64

#1 Hello worldの表示
image.png

参考リンク

Goのgetting started(入門講座)
https://go.dev/doc/

Installing Go

1. Goのインストール

windows版をインストール

1.2 VSCodeのインストール

 https://zenn.dev/em0/articles/41bbfb9aae6bb9240fa9
 を参照。
 https://code.visualstudio.com/docs/?dv=win

Step3: VSCodeの設定でエラーになる。

 command 'go.tools.install' not found
なぜか>go mod init v2 でエラーが出なくなった。

>go mod init
go: cannot determine module path for source directory C:\Users\skane\hello (outside GOPATH, module path must be specified)

Example usage:
        'go mod init example.com/m' to initialize a v0 or v1 module
        'go mod init example.com/m/v2' to initialize a v2 module

Run 'go help mod init' for more information.

Goのワークスペース"go env"コマンドで確認できる

go env
GOPATH=C:\Users\skane\go。

2. Tutorial: Get started with Go

・cmdを開く
・helloディレクトリを作る

Enable dependency tracking for your code.

 "go mod init" してみる。
 goのmoduleを作るコマンド。codeを実行するときに必要。
 https://pkg.go.dev/cmd/go#hdr-Initialize_new_module_in_current_directory

In your text editor, create a file hello.go in which to write your code.

テキストエディタ(VSCode)でhello.goを作る。
 File > New text file >select a language "go"
Ctrl + S
 C:\Users\skane\hello に保存する。

Paste the following code into your hello.go

package main : fanctionの塊。
import : fmt  fmtパッケージをインポートする。 stringとか数字とか
function main : コンソールに表示されるメイン。

Run your code to see the greeting.

C:\Users\skane\hello>go run hello.go
Hello, World!

できた!

Call code in an external package 他の人の作ったパッケージを使う。

pkg.go.dev siteで、moduleを見つけれて自分のプログラムに使える。
go mod tidy コマンドを入力すると、必要なmodがダウンロードされる?
 - quote (rsc.io/quote/v4)

C:\Users\skane\hello>go run rsc.go
Don't communicate by sharing memory, share memory by communicating.

失敗しているっぽいけど、これでいいらしい。

0
0
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
0
0