宣言 - Go

最終更新日: 2026-07-25

TOP(About this memo)) > 一覧(Go) > 宣言

代入可能性

https://go.dev/ref/spec#Assignability

変数宣言

https://go-tour-jp.appspot.com/basics/12

var i int
var f float64
var b bool
var s string

型推論

変数宣言のショートハンド

a := 1
a := 2 //再宣言としてエラーになる。
a := 1
a,b := 2,3

その他ショートハンド

定数

定数宣言ってあんまり使わない?

iota

const (
    zero  = iota // 0
    one/* = iota // 1 (省略可)*/
    two/* = iota // 2 (省略可)*/
    three/* = iota //3 (省略可)*/
)
type HttpRequestType int

const (
	_ HttpRequestType = iota
	HttpTypeGet
	HttpTypePost
)
func HttpDo(url string, requestType HttpRequestType, token string, body string) (string, error) {
  ...
}