🗂️
Goデスクトップリファレンス(オフィシャルサイトリンク集)
はじめに
思い出したいことが、そこにある。もしものときの クリック
リファレンス
全般
Webサイト
ダウンロード
リリースノート
Goブログ
GitHubリポジトリ
標準ライブラリ
インストールから初期モジュール生成まで
インストール
Hello, World!
A Tour of Go
モジュール生成
文法
型
基本型
- https://go.dev/ref/spec#Types
-
https://go-tour-jp.appspot.com/basics/11
- 特別な理由がない限り、整数の変数が必要な場合は int を使う
- https://go.dev/doc/faq#q_int_sizes
変数宣言
- https://go.dev/ref/spec#Variable_declarations
- https://go-tour-jp.appspot.com/basics/8
- https://go.dev/doc/effective_go#variables
- https://go.dev/ref/spec#Short_variable_declarations
- https://go-tour-jp.appspot.com/basics/10
型変換
- https://go.dev/ref/spec#Conversions
- https://go.dev/ref/spec#Conversions_to_and_from_a_string_type
- https://go-tour-jp.appspot.com/basics/13
ゼロ値
-
https://go.dev/ref/spec#The_zero_value
- false for booleans, 0 for numeric types, "" for strings
- https://go-tour-jp.appspot.com/basics/12
リテラル
- https://go.dev/ref/spec#Integer_literals
- https://go.dev/ref/spec#Rune_literals
- https://go.dev/ref/spec#String_literals
定数宣言
- https://go-tour-jp.appspot.com/basics/15
-
https://go.dev/doc/effective_go#constants
- In Go, enumerated constants are created using the iota enumerator.
表示フォーマット
演算子
-
https://go.dev/ref/spec#Arithmetic_operators
-
+
also applies to strings.
-
- https://go.dev/ref/spec#IncDec_statements
ポインタ
コレクション
配列
- https://go.dev/ref/spec#Array_types
- https://go-tour-jp.appspot.com/moretypes/6
- https://go.dev/doc/effective_go#arrays
- https://go.dev/doc/faq#references
スライス
- https://go.dev/ref/spec#Slice_types
- https://go-tour-jp.appspot.com/moretypes/7
- https://go.dev/doc/effective_go#slices
- https://go.dev/wiki/CodeReviewComments#declaring-empty-slices
- https://go.dev/blog/slices-intro
マップ
- https://go.dev/ref/spec#Map_types
- https://go-tour-jp.appspot.com/moretypes/19
-
https://go.dev/doc/effective_go#maps
- A set can be implemented as a map with value type bool.
- https://go.dev/doc/faq#atomic_maps
構造体
- https://go.dev/ref/spec#Struct_types
- https://go-tour-jp.appspot.com/moretypes/2
- https://go.dev/ref/spec#Composite_literals
エイリアス
制御構文
if文
- https://go.dev/ref/spec#If_statements
- https://go.dev/ref/spec#Comparison_operatorss
- https://go.dev/ref/spec#Logical_operators
- https://go-tour-jp.appspot.com/flowcontrol/5
- https://go.dev/doc/effective_go#if
- https://go.dev/wiki/CodeReviewComments#indent-error-flow
switch文
- https://go.dev/ref/spec#Switch_statements
- https://go-tour-jp.appspot.com/flowcontrol/9
- https://go.dev/doc/effective_go#switch
- https://google.github.io/styleguide/go/decisions#switch-and-break
for文
- https://go.dev/ref/spec#For_statements
- https://go.dev/ref/spec#For_range
- https://go-tour-jp.appspot.com/flowcontrol/1
- https://go.dev/doc/effective_go#for
- https://go.dev/ref/spec#Break_statements
- https://go.dev/ref/spec#Continue_statements
関数
- https://go.dev/ref/spec#Function_declarations
- https://go.dev/ref/spec#Passing_arguments_to_..._parameters
- https://go-tour-jp.appspot.com/basics/4
- https://go.dev/doc/effective_go#functions
- https://go.dev/ref/spec#Function_types
- https://go-tour-jp.appspot.com/moretypes/24
defer
メソッド
- https://go.dev/ref/spec#Method_declarations
- https://go-tour-jp.appspot.com/methods/1
- https://go.dev/doc/effective_go#methods
インターフェース
- https://go.dev/ref/spec#Interface_types
- https://go-tour-jp.appspot.com/methods/9
- https://go.dev/doc/faq#implements_interface
空インターフェース
- https://go-tour-jp.appspot.com/methods/14
-
https://go.dev/doc/go1.18#generics
- The new predeclared identifier
any
is an alias for the empty interface. It may be used instead of interface{}.
- The new predeclared identifier
型アサーション
型switch
埋め込み
- https://go.dev/ref/spec#Struct_types
- https://go.dev/ref/spec#Embedded_interfaces
- https://go.dev/doc/effective_go#embedding
ゴルーチン
- https://go.dev/ref/spec#Go_statements
- https://go-tour-jp.appspot.com/concurrency/1
- https://go.dev/doc/effective_go#goroutines
- https://go.dev/doc/faq#no_goroutine_id
- https://google.github.io/styleguide/go/decisions#goroutine-lifetimes
チャネル
- https://go.dev/ref/spec#Channel_types
- https://go.dev/ref/spec#Send_statements
- https://go-tour-jp.appspot.com/concurrency/2
- https://go.dev/doc/effective_go#channels
select文
-
https://go.dev/ref/spec#Select_statements
- If one or more of the communications can proceed, a single one that can proceed is chosen via a uniform pseudo-random selection.
- https://go-tour-jp.appspot.com/concurrency/5
- https://go.dev/blog/concurrency-timeouts
Mutex
文字列の文字シーケンスとバイトシーケンス
- https://go.dev/ref/spec#Conversions_to_and_from_a_string_type
-
https://go.dev/ref/spec#Index_expressions
- a[x] is the non-constant byte value at index x and the type of a[x] is byte
-
https://go.dev/ref/spec#For_range
- For a string value, the "range" clause iterates over the Unicode code points in the string starting at byte index 0.
- https://go.dev/blog/slices#strings
- https://go.dev/blog/strings
パッケージ
- https://go.dev/ref/spec#Packages
-
https://go.dev/ref/spec#Import_declarations
- If the PackageName is omitted, it defaults to the identifier specified in the package clause of the imported package.
- https://go-tour-jp.appspot.com/basics/1
公開識別子(アクセス修飾子)
ガイドライン
ネーミング
全般
変数
- https://go.dev/wiki/CodeReviewComments#variable-names
-
https://google.github.io/styleguide/go/decisions#variable-names
- the length of a name should be proportional to the size of its scope and inversely proportional to the number of times that it is used within that scope.
レシーバ
- https://go.dev/wiki/CodeReviewComments#receiver-names
- https://google.github.io/styleguide/go/decisions#receiver-names
定数
エラー
パッケージ
- https://go.dev/doc/effective_go#package-names
- https://go.dev/blog/package-names
- https://google.github.io/styleguide/go/decisions#package-names
コンテキスト
-
https://pkg.go.dev/context
- which carries deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes.
-
https://go.dev/wiki/CodeReviewComments#contexts
- Most functions that use a Context should accept it as their first parameter
- https://go.dev/blog/context
- https://go.dev/blog/context-and-structs
エラーハンドリング
- https://go-tour-jp.appspot.com/methods/19
- https://go.dev/doc/effective_go#errors
- https://google.github.io/styleguide/go/decisions#handle-errors
-
https://google.github.io/styleguide/go/decisions#errors
- By convention, error is the last result parameter.
- https://go.dev/blog/errors-are-values
Unwrap、Is、As
panic
- https://go.dev/wiki/CodeReviewComments#dont-panic
- https://go.dev/doc/effective_go#panic
- https://go.dev/blog/defer-panic-and-recover
おまけ
日時
ログ
FAQ
- なぜ変数宣言をC言語と逆にしたの?
- https://go.dev/doc/faq#declarations_backwards
- https://go.dev/blog/declaration-syntax
- 気にしないで慣れて。モダンな静的型付け言語の流れとしては、むしろ多数派
- Goはオブジェクト指向言語?
- https://go.dev/doc/faq#Is_Go_an_object-oriented_language
- 別アプローチの提供が主目的。アンチパターンは予防しているがオブジェクト指向スタイルのプログラミングもできると思う
- なぜ継承がないの?
- https://go.dev/doc/faq#inheritance
- has-a関係をis-a関係にミスリードしてる。継承より・・・
- なぜオーバーロードできないの?
- https://go.dev/doc/faq#overloading
- 引数の並び順だけ入れ替えたりされると混乱するから関数名変えて違いを表現して
- なぜExceptionがないの?
- https://go.dev/doc/faq#exceptions
- 技術的負債の温床。非チェック例外のthrowは第2のgoto
- なぜアサーションがないの?
- https://go.dev/doc/faq#assertions
- エラーとしてハンドリングしてもらった方が安心できる
- なぜスレッドではなくゴルーチンなの?
- https://go.dev/doc/faq#goroutines
- CPUとメモリの無駄遣いになるからシステムコールしたくない
- レシーバは値とポインタのどちらにすべき?
- https://go.dev/doc/faq#methods_on_values_or_pointers
- レシーバがstructで、それをclassスタイルで扱いたいならポインタ。値はエキスパート向け
- ガベージコレクションがあると負担になるのでは?
- https://go.dev/doc/faq#garbage_collection
- 進歩したテクノロジーを活用しないのは大きな損失。いかにして許容誤差に収めるかを考えるのが賢明
- 変数のメモリ割り当てがヒープになるかスタックになるか、どのように決められるの?
- https://go.dev/doc/faq#stack_or_heap
- 言語のセマンティクスとは無関係なので明文化する気はない。合理的に最適化していく
- Goのランタイムの役割は?
- https://go.dev/doc/faq#runtime
- libcを不要にする。なので distroless/static をベースイメージに使える
おわりに
後ろ盾になるオフィシャルの見解を知りたいベスト3
第3位
null safetyは?
第2位
if expressionは?
第1位
immutableは?
Discussion