Goèšèªã¯Googleã«ãã£ãŠéçºãããProgramming Languageãã·ã³ãã«ããã³ã³ã»ããã«ããŠãããšãããDockerã¯Goã§æžãããŠããã
Understanding Nil in Go: Unique Comparison Behaviors | by Beck Moulton | Jan, 2024 | Level Up Coding
Goã®nilãç解ããã
Goèšèªã§ãããã¡ãªééãã
oapi-codegenã®äœ¿ãæ¹ããšãã«ããªããŒã·ã§ã³ãåèã«ãªãã
[[https://note.crohaco.net/2020/gorp-unittest-with-db/][[Golang] gorpã§DBã䜿ã£ããŠããããã¹ããæžããã£ãã²ãšã€ã®åŽãããããã - ããã®ãŠ]]
factory-botã䟿å©ã«äœ¿ãæ¹æ³ã
åŒæ°ã«ãã€ã³ã¿ããšããšããâã®ããã«ããããªãã
i := 1
xxxx(&i)
å®éã¯âã®ããã«çãæžããã
func GetPtr[T any](x T) *T {
return &x
}
xxxx(GetPtr(1))
func main() {
done := make(chan bool)
values := []string{"a", "b", "c"}
for _, v := range values {
go func() {
fmt.Println(v)
done <- true
}()
}
// wait for all goroutines to complete before exiting
for _ = range values {
<-done
}
}
v
ã«å ¥ãã€ã³ã¹ã¿ã³ã¹ã¯ã«ãŒãéã§å ±éã§ãã- ã«ãŒãããŸããåã£ãŠãããgoã«ãŒãã³ãå®è¡ããããgoã«ãŒãã³ãå®è¡ããããšãã«ã¯ãã€ã³ã¹ã¿ã³ã¹ã¯æåŸã®
"c"
ã«ãªã£ãŠãã
gdbã ãšè¬ã®goroutineããããã®ããã³ãã³æ¿å
¥ããã( runtime.sigtramp
)ãçŽãæ¹ãããããããªãã®ã§ãããã代ããã«delveã䜿ãããšã«ãæ§é äœã®è¡šç€ºãããæãã ã䜿ãæ¹ã¯ã ãããåãã
Emacsã® M-x gdb
ãšåçã«ãªãã®ãbenma/go-dlv.elã§é
åžãããŠãããdap-modeãããã¡ãã奜ã¿ã (dlv-current-func)
ã䜿ãã
ã³ã³ãã€ã«æã«æé©åããçµæãå€æ°ãåŒãåé€ããããšãããããã®å Žåãããã¬ã§è¡šç€ºã§ããªããªããã³ã³ãã€ã«ãªãã·ã§ã³ã§æé©åãç¡å¹åãããšè¡šç€ºã§ããã
go build -gcflags="-N -l" main.go
ãªãã·ã§ã³ããããããããã§ããã³ãŒãããŒã¹ã§èŠãè¡šçŸã®è§£èª¬ãèŠã€ããã
package main
import "fmt"
type Config struct {
Host string
Port int
Username string
Password string
}
type Option func(*Config)
func WithHost(host string) Option {
return func(c *Config) {
c.Host = host
}
}
func WithPort(port int) Option {
return func(c *Config) {
c.Port = port
}
}
func WithCredentials(username, password string) Option {
return func(c *Config) {
c.Username = username
c.Password = password
}
}
func NewConfig(options ...Option) *Config {
config := &Config{
Host: "localhost",
Port: 8080,
Username: "",
Password: "",
}
for _, option := range options {
option(config)
}
return config
}
åã§æåãå€ããæžãæ¹ãã§ããã
type Mover bool
const (
Animate = Mover(true)
DontAnimate = Mover(false)
)
func (m Mover) move() { }
Animate.move()
DontAnimate.move()
Goèšèªã«ãã䞊è¡åŠçããã
ãŽã«ãŒãã³ã®äžã§ã¯ããŒãžã£ãŒãå®è¡ãããšãã¯ããŒãžã£ãŒã¯ãããã®å€æ°ã®ã³ããŒã«å¯ŸããŠæäœããã®ãããããšãå ã®å€æ°ã®åç §ã«å¯ŸããŠãã
var wg sync.WaitGroup
salutation := "hello"
wg.Add(1)
go func() {
defer wg.Done()
salutation = "welcome"
}()
wg.Wait()
fmt.Println(salutation)
ãŽã«ãŒãã³ã¯ãããäœãããã¢ãã¬ã¹ç©ºéãšåã空éã§å®è¡ããããšããããšã
var wg sync.WaitGroup
for _, salutation := range []string{"hello", "greetings", "good day"} {
wg.Add(1)
go func() {
defer wg.Done()
fmt.Println(salutation)
}()
}
wg.Wait()
- ãŽã«ãŒãã³ãéå§ããåã«ã«ãŒããçµäºããŠããŸã
- salutationå€æ°ã¯ã¹ã³ãŒãå€ã«ãªã
- Goã©ã³ã¿ã€ã ã¯å€æ°salutationã®åç §ããŸã ä¿æãããŠããã®ãç¥ã£ãŠããŠããŽã«ãŒãã³ããã®ã¡ã¢ãªã«ã¢ã¯ã»ã¹ãç¶ããããããã«ã¡ã¢ãªãããŒãã«ç§»ã
- æååã¹ã©ã€ã¹ã®æåŸã®âgood dayâãžã®åç §ãä¿æãããŸãŸããŒãã«ç§»ããã
ã«ãŒããæ³å®ããããã«ãã ããæžãã«ã¯ãsalutationã®ã³ããŒãã¯ããŒãžã£ãŒã«æž¡ããŠããŽã«ãŒãã³ãå®è¡ãããããã«ãªããŸã§ã«ã«ãŒãã®åç¹°ãè¿ãããæž¡ãããããŒã¿ãæäœã§ããããã«ããã
var wg sync.WaitGroup
for _, salutation := range []string{"hello", "greetings", "good day"} {
wg.Add(1)
go func(salutation string) {
defer wg.Done()
fmt.Println(salutation)
}(salutation)
}
wg.Wait()
åå ã¯ããããããªããããŒã«ãã€ã³ã¹ããŒã«ããŠãã©ãŒãããããããã
main.go:24: File is not `gci`-ed with âskip-generated -s standard,default (gci)
go install github.com/daixiang0/gci@latest
gci write --skip-generated -s standard,default .
ã«ãã¬ããžãã©ã°ããªã³ã«ããŠãããšã³ã³ãã€ã«æãåãããã¯ã«ã«ãŠã³ã¿ãæ¿å ¥ãããŠå®è¡ãããŠããã
ãã¡ã€ã«æå®ã§ãã¹ããå®è¡ããããšãããšãã»ãã®ããã±ãŒãžãèªã¿èŸŒãã§ãããªãããèµ°ãããããªãããšããããå€ãã®å Žåãã»ãã®ãã¡ã€ã«ãžã®èªã¿èŸŒã¿ãããã®ã§ãçŸå®çã§ã¯ãªãããªã®ã§ãèªã¿èŸŒããã¡ã€ã«ã¯å šäœã«ããŠãèµ°ãããé¢æ°ãæå®ããŠäžéšã ãå®è¡ããã
go test ./... -run Buildinfo
- ã¡ã¢ãªã®èªã¿æžããè¡ãå Žæã¯ãã¹ã¿ãã¯ãšããŒãã«åããã
- ã¹ã¿ãã¯ã¯ã¡ã¢ãªã®äœ¿ãæ¹ã䜿çšéãã³ã³ãã€ã«æã«æ±ºå®ã§ããå Žåã«çšãããã
- é¢æ°åŒã³åºãæã«ç¢ºä¿ãããé¢æ°ããæãããšãã«éæŸãããã
- ãããããã©ã®ã¡ã¢ãªãã©ãã ã䜿ããããã£ãŠãããããå¿ èŠã«ãªãçŽåã§ç¢ºä¿ãããããªããªã£ããããã«ç Žæ£ã§ãã¡ã¢ãªãå¹çãã䜿ãã
- ããŒãã¯ã¡ã¢ãªã®äœ¿ãæ¹ã䜿çšéãå®è¡æã«ããããããªãå Žåã«çšãã
- ããŒãã«ç¢ºä¿ããå€æ°ã®çåæéã¯çšéã«ãã£ãŠãã©ãã©
- ã¬ããŒãžã³ã¬ã¯ã¿ãçšããŠããŒãã®ã¡ã¢ãªãéäžç®¡çãããããã¹ãã¿ã€ãã³ã°ã§è§£æŸãã
- Goã§ã¯GCæã«STW(Stop The World)ãçºçãããã®ãæ¡çšããŠããã®ã§ãGCãåããŠããéã¯ããã°ã©ã ã®å®è¡ãæ¢ãŸã
- ãªã®ã§ãããã©ãŒãã³ã¹ãèæ ®ãããšãã¯ã¡ã¢ãªã確ä¿ããå ãã¹ã¿ãã¯ã«ãªããããŒãã«ãªããã¯éèŠ
- å€æ°ã®åãå®æ ã§å®çŸ©ãããå ŽåãGoã¯ãã®å€æ°ãã¹ã¿ãã¯äžã«ç¢ºä¿ãããCèšèªãšåã
- å€æ°ã®åããã€ã³ã¿ã«ãããšãã¡ã¢ãªã¯ããŒããã¹ã¿ãã¯ã®ã©ã¡ããã«ç¢ºä¿ããã
- ã¹ã¿ãã¯ã¯ã¡ã¢ãªã®äœ¿ãæ¹ã䜿çšéãã³ã³ãã€ã«æã«æ±ºå®ã§ããå Žåã«çšãããã
- os.CreateTemp ã䟿å©
- os.MkdirTemp â ãã£ã¬ã¯ããª
- (*testing.T).TempDir â ãã¹ãã§äŸ¿å©ããã¹ãé¢æ°ã®çµäºæã«ãã£ã¬ã¯ããªãæ¶ããŠããã
fmt.Print(unicode.IsUpper('a'))
fmt.Print(unicode.IsUpper('A'))
goimportsã¯é¢åãªimportãèªåã§æžããŠããã䟿å©ãªããã±ãŒãžãå¿ èŠãªããã±ãŒãžãèªåã§æ¶ããŠããŸãã®ã§ããã£ãããã§ãã¯ãªã¹ããæ®ãã
- ååã¯åã£ãŠããããç¹ã«èªåã®ããã±ãŒãžãèªã¿èŸŒãå ŽåãmoduleåãšäžèŽããŠããã
- æ¬åœã«ãã®ç®æããèªã¿èŸŒããŠããèšè¿°ã«ãªã£ãŠããããpublicãªåŒã³åºãã«ãªã£ãŠããã
copyã¯ãã®åã®éãsliceãã³ããŒããã¡ãœãããåºå®é·ã§ãªããšã³ããŒãããªãã
$ go test -coverprofile=cover.out .
$ go tool cover -html=cover.out -o cover.html
Golang/goã®ãªããžããªå šäœãèšæž¬ããã
cd ./src
./all.bash
../bin/go test -cover ./... -coverprofile=cover.out
../bin/go tool cover -html=cover.out -o cover.html
godoc -http ":8000" -analysis type
# http://localhost:6060/pkg/io/
func (w *Wallet) Withdraw(amount Bitcoin) error {
if amount > w.balance {
return ErrInsufficientFunds
}
w.balance -= amount
return nil
}
æåãããšãã¯ãerrorã«nilãå ¥ãã
erroræã®åŠçã¯åŒã³åºãå ã§å®çŸ©ããerrorãè¿ãå¯èœæ§ã®ããé¢æ°å®çŸ©ã§ã¯åã«errorãè¿ãããšã ãã«éäžããã
è¿ãå€ã«ååãã€ããæ©èœãæåã«åæåãããreturnãããšããæç¹ã®ååã®ã€ããå€æ°ãè¿ãããã
func test() (value1, value2 int) {
value1 = 1
value2 = 2
return
}
ãšãããšãè¿ãå€ã«ã¯1, 2ãè¿ããé·ãé¢æ°ã ãšãããã¥ãããªãã®ã§æ³šæã
ã©ã®é¢æ°ãã©ãããåŒã³åºãããŠãããã®å³ãçæããã
go install github.com/ofabry/go-callvis@master # ãªããlatestããŒãžã§ã³ã§ã¯å€±æãã
ãããŠèª¿ã¹ããé¢æ°ãåŒã³åºããmain.goã®ãããã£ã¬ã¯ããªã§å®è¡ããã
go-callvis -group pkg,type ./ # -groupã¯ã°ã«ãŒãã³ã°è¡šç€ºãããªãã·ã§ã³
go-callvis -group pkg,type -focus fmt ./ # ãã©ãŒã«ã¹è¡šç€º
ãšããã©ãŠã¶ãç«ã¡äžãã£ãŠãå³ã衚瀺ããããå³ã®äžã®ã©ã€ãã©ãªãã¯ãªãã¯ãããšãããã«ãã®ã©ã€ãã©ãªã®åŒã³åºããæç»ããã
go get ãããšã x509: certificate signed by unknown authority
ãšã©ãŒã«ãªãã
蚌ææžã®æŽæ°ãããã°ãããšã®ããšã
$ sudo apt update
$ sudo apt install --only-upgrade -y ca-certificates #ææ°
$ update-ca-certificates
ãªã¯ãšã¹ãã䜿ããšãã«é垞䜿ãããæ¹æ³ãå€ã®æ€èšŒãšåŸã§å©çšãããããããããå®çŸ©ããæ§é äœã«å ¥ããã
Goã®åã蟌ã¿ã®è§£èª¬ã
åã蟌ã¿ã¯ãããŸã§ãåããŠããã ãã§ãåã蟌ã¿å ã®ãªããžã§ã¯ãã®ã¡ãœãããšããŠå®è¡ããããåã蟌ã¿å ã®æ§é äœãåã蟌ã¿å ã®ã¡ãœãããå®è¡ããŠãåã蟌ã¿å ã®ãªããžã§ã¯ãã«ã¯åœ±é¿ãäžããªãã
å³ã«ãããã€ã³ã¿ã®ãããããã解説ãvar x = 100
fmt.Println("1: x address:\t", &x)
var y *int
fmt.Println("2: y value:\t", y)
fmt.Println("3: y address:\t", &y)
y = &x
fmt.Println("4: y value:\t", y) // yã®å€ã«ã¯ãxã®ã¢ãã¬ã¹ãå
¥ã£ãŠãã
fmt.Println("5: y address:\t", &y)
- åãšããŠã®
*
- ãã€ã³ã¿å€æ°ã¯ã¡ã¢ãªäžã®ã¢ãã¬ã¹ãå€ãšããŠå ¥ããããå€æ°
- å€æ°ã®äžèº«(ã€ãŸãå€)ã¯ã¡ã¢ãªã¢ãã¬ã¹
- å€æ°ã®æŒç®åãšããŠã®
*
,&
*
ãã€ã³ã¿ã®æãã¡ã¢ãªã¢ãã¬ã¹ã®å®ããŒã¿(value)&
å€æ°ãã¡ã¢ãªäžã§ç¢ºä¿ãããéã®ã¢ãã¬ã¹(address)
*x
ã ãã© x
ããã€ã³ã¿åå€æ°ã§ãªãå Žåãå€ã«ã¢ãã¬ã¹ããªããŠèŸ¿ããåœç¶å€ãååŸã§ããªãã®ã§ãšã©ãŒã
- ã¡ã¢ãªã¢ãã¬ã¹ã¯å€æ°ã§ããã°å¿
ãååšããããªã®ã§ã©ã®å€æ°ã§ã
&
ã䜿ãã - valueã¯å€(1)ããã¡ã¢ãªã¢ãã¬ã¹(0xc00001a0c0)ãå
¥ã£ãŠããããnilãå€ã«ã¡ã¢ãªã¢ãã¬ã¹ãå
¥ã£ãŠããå Žåã®ã¿
*
ã䜿ãã
var x *int
fmt.Println("x value:\t", *x)
ãã€ã³ã¿å€æ°ã®valueã«ã¡ã¢ãªã¢ãã¬ã¹ããªãã®ã§panicãèµ·ãããåãããŠã¿ãªããšããããªãã®ã§ã³ã³ãã€ã«ãšã©ãŒã§ãªãruntimeãšã©ãŒã
Goã¯ãã¹ãŠå€æž¡ã(=ã³ããŒ)ã
func main() {
var x = "alice"
fmt.Println("x address:\t", &x)
y := &x
fmt.Println("y value:\t", y)
fmt.Println("y address:\t", &y)
show(y)
}
func show(s *string) {
fmt.Println("f value:\t", s)
fmt.Println("f address:\t", &s)
}
å®çŸ©ãããå€æ°ãšãé¢æ°åŒæ°ãšããŠäœ¿ãããå€æ°ã§ã¯ãåç §å ã¢ãã¬ã¹ã¯åã(xã®ã¢ãã¬ã¹)ãã¢ãã¬ã¹ã¯ç°ãªããã€ãŸãã³ããŒãããŠããã
ãã€ã³ã¿ã¬ã·ãŒãã
type Person struct {
Name string
Age int
}
func main() {
x := &Person{"alice", 20}
fmt.Printf("x value:\t%p\n", x)
fmt.Printf("x address:\t%p\n", &x)
x.Greet("test")
fmt.Printf("new x value:\t%v\n", x)
}
func (p *Person) Greet(msg string) {
fmt.Printf("p value:\t%p\n", p)
fmt.Printf("p address:\t%p\n", &p)
// ãã€ã³ã¿å€æ°ãäžæžãããã®ã§ã¯ãªããåç
§å
ãäžæžããã
p.Name = "hahaha"
}
ã¡ãœããã®ã¬ã·ãŒããŒãå€ã«ããããã€ã³ã¿ã«ãããã¯ãã¬ã·ãŒãã®ãã£ãŒã«ãã«å€æŽãããããã«ãã£ãŠæ±ºããã
func (s Struct) SetValue(v int {
s.v = v
})
func (s *Struct) SetValue(v int {
s.v = v
})
- ãã€ã³ã¿åã瀺ããšãã¯
*Person
ãšå®£èšãããã«ãã£ãŠPersonåã®å€æ°ã®ãã€ã³ã¿ãå ¥ãããšã瀺ããã - ãã€ã³ã¿åãçæãããšãã¯
&
ã䜿ããããã¯å€æé¢æ°ã®ãããªãã®ã&å€æ°å
ãšãã圢åŒãå®éã«å€æ°å®£èšãããŠãããã®ã«å¯ŸããŠãã€ã³ã¿ããããããããã«ã¢ãã¬ã¹ãå²ãåœãŠããããããªãã®ãã ãããåãšãé¢æ°èªäœã¯ãã€ã³ã¿ã«ããªã(æå³ããªã)ããããŸã§å€æ°ããªã³ã¯ãããŠãå€æŽãæ³¢åãããããã®ãè¯ããšããã ãã - ãã€ã³ã¿ã解決å®éã®å€ãèŠããšã㯠*p
- &p ã§*Personåãçæããããšãããããªé¢ä¿æ§
var p *int // å€æ°pã«ã¯ãintåã®å€æ°ã®ãã€ã³ã¿ãå
¥ããšãã宣èš
i := 1
p = &i // å€æ°iãåç
§ãããã€ã³ã¿åå€æ°p
// p // -> 0xc000010000
// *p // -> 1
fmt.Println(p)
fmt.Println(*p)
i = 2 // ãããŸã§å€ããã®ã¯åç
§å
ã®å€ã§ãã£ãŠãp -> i ã®ãªã³ã¯èªäœãå€ãããããããªã
fmt.Println(p) // ã¡ã¢ãªã¢ãã¬ã¹ã¯å€ãããªã
fmt.Println(*p) // åç
§å
ã®ã¢ãã¬ã¹ãå€ãã£ã
- ãã¢ãã¬ã¹ãååŸ(&)ããšããæäœãšãã¢ãã¬ã¹ã解決(*)ããšããæäœãããã
ååšãã§ãã¯ã®æ¹æ³ã
//go:embed sample.json
var sampleBytes []byte
ãã¡ã€ã«ãçŽã«å€æ°ã«å ¥ããããšãã§ããããã¡ãã¡èªã¿èŸŒã¿ã®ã³ãŒããæžããªããŠè¯ããªãã
è€æ°ãã¡ã€ã«ã®åã蟌ã¿ãã§ããã
//go:embed README.md version.txt
var static embed.FS
r, err := static.Readfile("README.md")
確ãã«çãæžããããããããã ããªããåŸæ¥ã®æ¹æ³ã§ãã§ãããã¡ãªããã¯ãèšå®ãã¡ã€ã«ããã€ããªã«åã蟌ããããšã
ååãšåãå€æ°åã宣èšãããšãããããŒã«ã«ãªå€æ°åãåªå ãããããããã®åã䜿ããªããªããããã ãã§ãªããåæå®ã§~ã¯åã§ã¯ãããŸãããšã©ãŒãè¬ã«åºãããããããå¯èœæ§ãé«ããLintã§é²ããã ãããã
- fdã¯ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãããã°ã©ã ãããã¡ã€ã«ãæäœããéãæäœå¯Ÿè±¡ã®ãã¡ã€ã«ãèå¥ã»åå®ããããã«å²ãåœãŠãããçªå·
https://github.com/kd-collective/go/blob/a813be86df74bf2a9c5b272c0b0934d196ac665d/src/os/file_unix.go#L54-L61
- ãããã¯ãŒã¯ã§äœ¿ãConnã€ã³ã¿ãŒãã§ãŒã¹
https://github.com/kd-collective/go/blob/a813be86df74bf2a9c5b272c0b0934d196ac665d/src/net/net.go#L113-L168
- Open(), Create() ã¯åŒæ°ãéãã ãã§åãé¢æ°OpenFile()ãåŒã³åºããŠãã
- ãã䜿ãæš©éã®çµã¿åããã§ã©ããããŠããã ã
https://github.com/kd-collective/go/blob/a813be86df74bf2a9c5b272c0b0934d196ac665d/src/os/file.go#L311-L313
https://github.com/kd-collective/go/blob/a813be86df74bf2a9c5b272c0b0934d196ac665d/src/os/file.go#L320-L322
https://github.com/kd-collective/go/blob/a813be86df74bf2a9c5b272c0b0934d196ac665d/src/os/file.go#L330-L339
go mod init example
go install
go run hello.go
Emacs dap-modeã§ãããã¬èµ·åãè¡ã®æšªãã¯ãªãã¯ããŠãã¬ãŒã¯ãã€ã³ããã»ããããã®ã¡ãã³ãã³ãå®è¡ã
M-x dap-debug
ob-goãã€ã³ã¹ããŒã«ã㊠(require "ob-go")
ãããå®è¡æ¹æ³ãå°ãå€ãã£ãŠããŠãäžã®ããã«æå®ããã
fmt.Println("hello world")
Goçšã®ãããã¬ã¯emacsã³ãã³ãã§ã€ã³ã¹ããŒã«ã§ãããgo installã§ã€ã³ã¹ããŒã«ããå¿ èŠãããã
- Configuration - DAP Mode
- å€éšã³ãã³ããgo installã§ã€ã³ã¹ããŒã«
- LSPã®ã©ã€ãã©ãªåã¯
gopls
- Debuggerã®ã©ã€ãã©ãªåã¯
delve
(泚æ: VScodeçšã®ããã°ã©ã ãçšããæ¹æ³ã¯deprecatedã§ãçŸåšã¯çŽæ¥installããã®ãææ°)
- LSPã®ã©ã€ãã©ãªåã¯
- go installããããšãEmacsåŽãèªèã§ããããã«èšå®ãã
- å€éšã³ãã³ããgo installã§ã€ã³ã¹ããŒã«
$ go install golang.org/x/tools/gopls@master # Language Server
$ go install github.com/go-delve/delve/cmd/dlv@master # debugger
èªåã®ç°å¢ã§ã¯äžç¬ãããã¬ã®ãã¿ã³ã衚瀺ãã㊠Debug Adapter finished ã«ãªã£ãŠããŸãç¶æ
ã«ãªã£ããWarningã«ã¯ Warning (emacs): Initialize request failed: Failed to launch Disable showing Disable logging
ã衚瀺ããããçç±ãããããããªãããã衚瀺ãããã (setq dap-print-io t)
ãè©äŸ¡ãããšãmessageãããã¡ã«è©³çŽ°ãªãã°ãåºåããã
åå ã¯ããã£ãããšè¡šç€ºãããŠããã
âformatâ: âFailed to launch: Go version 1.14.15 is too old for this version of Delve (minimum supported version 1.17, suppress this error with âcheck-go-version=false)â,
ãšããããšã§ãgoã®ããŒãžã§ã³ãäžãããšç¡äºãããã¬ãèµ·åããããã«ãªã£ãã
$ go install github.com/uudashr/gopkgs/cmd/gopkgs # Go ããã±ãŒãž
$ go install golang.org/x/tools/cmd/goimports@master # import ã®éäžè¶³ãèªåã§è£å®
ããªã³ã¿ãŒã®ç¶æ ãä¿åããŠãããéèŠãããªæ§é äœã
https://github.com/golang/go/blob/122a22e0e9eba7fe712030d429fc4bcf6f447f5e/src/fmt/print.go#L119-L120
https://github.com/golang/go/blob/122a22e0e9eba7fe712030d429fc4bcf6f447f5e/src/fmt/print.go#L188-L202
https://github.com/golang/go/blob/122a22e0e9eba7fe712030d429fc4bcf6f447f5e/src/fmt/print.go#L271-L273
- doPrintf
- printArg
- printValue
- printArg
- å®éç»é¢ã«è¡šç€ºããŠãã®ã¯ã©ããªãã ãã
- printç³»ã®äžã§bufã«æžã蟌ã¿ãããŠããã®ã¯ããèŠã
- é¢æ°ã®äžã«ç»é¢åºåãã¿ãããªéšåã¯èŠåœããã
- å¥ã«ãç»é¢ã«åºåããããšããé¢æ°ããããããããªããŠããæšæºåºåã«ããããã¡ã€ã«ã«æžã蟌ã¿ããããé¢æ°ãããã ããã ãããæšæºåºå以å€ãžã®æžã蟌ã¿ãšã®å·®ã¯äžåãªã
- /dev/stdin ã¯ç¹æ®ãã¡ã€ã«ãšãããç»é¢ãžã®å ¥åºåãªã©ããã¡ã€ã«ãšããŠæäœã§ããããã«ãããã®ã ããããã¡ã€ã«æžã蟌ã¿ãšãªããå€ãããã«æäœã§ãã
- Stdoutã¯1ãšå®çŸ©ãããŠããããªã®ã§ãfd1ã€ãŸã/dev/stdout/1ãäœæãã
https://github.com/kd-collective/go/blob/9b8750f53ed89fb326e4d811524e647683136bac/src/os/file.go#L66
https://github.com/kd-collective/go/blob/9b8750f53ed89fb326e4d811524e647683136bac/src/cmd/vendor/golang.org/x/sys/unix/syscall_unix.go#L20
- printç³»ã¯ãããŒã¹ã«ãªãé¢æ°ããããæžã蟌ã¿å ãšãã©ãŒããã解æã®çµã¿åããã§ãããããååãã€ããŠãã
- æ¬è³ªçã«ããã¡ã€ã«æžã蟌ã¿ã«ãããªã
- ãã©ãŒããã解æã§ããããåŠçããã£ãŠãå€ããå ãããååã§ã®æååã®åãåºãæ¹ãšã
https://github.com/kd-collective/go/blob/9b8750f53ed89fb326e4d811524e647683136bac/src/fmt/print.go#L63-L65
type MyString string
func (s MyString) String() string {
return "mystring"
}
func main() {
s := MyString("hello")
fmt.Println(s) // String()ã®çµæã䜿ããã
}
printãããšãã«ã¯ãå ã«Stringerã®å€å®ãå ¥ããStringerãæºãããŠããã°ãString()ã䜿ããæºãããªããã°ãéåžžã®ãprintã«æž¡ãããæåååŒæ°ã䜿ã£ãŠè¡šç€ºããã
https://github.com/kd-collective/go/blob/9b8750f53ed89fb326e4d811524e647683136bac/src/fmt/print.go#L670-L675
- Goã®runeãç解ããããã®Unicodeç¥è - Qiita
- æåãš01ã®äžŠã³ã察å¿ã¥ããä»çµã¿ããããæåã³ãŒãããã®1ã€ã®Unicodeã¯äžçäžã®ããããæååãåé²ãããããã«äœãããŠããèŠæ Œ
- aã¯Unicodeã§u+0041ãšè¡šãããã16é²æ°ã§0041ãšããå€ãšå¯Ÿå¿ã¥ããããããã®å€ã¯code point(code position)ãšåŒã°ããæåã³ãŒãäžã®äœçœ®ãæã瀺ãæåã®IDãšããã
- 笊å·åæ¹åŒã¯41ãšã1F601ãšãã£ãcode pointã®å€ãã³ã³ãã¥ãŒã¿ãæ±ãããŒã¿åœ¢åŒã«çœ®ãæããããã®èŠåãæ¹åŒã«ãã£ãŠcode pointãäœbyteåäœã§æ±ãããç°ãªã£ãŠãã
- Goã§ã¯ç¬Šå·åæ¹åŒãšããŠUTF-8ã䜿çšããŠãããUTF-8ã§ã¯1byteãã4byteã®å¯å€é·ããŒã¿ã§code pointã眮æãããæ°åãã¢ã«ãã¡ãããã®ãããªåºã䜿ãããŠããæåã¯1byteã«ãªããUnicodeã«åŸããè¿œå ãããçµµæåãªã©ã¯4byteã«ãªãã
- Unicodeã®ç¬Šå·åæ¹åŒã«ã¯UTF-16ãUTF-8ããã
- stringã«ã€ã³ããã¯ã¹ã§ã¢ã¯ã»ã¹ãããšãã«åŸãããbyteå€ã¯æåã³ãŒããUTF-8ã§1byteããšã«åºåã£ãå€
s := "ã"
for i := 0; i < len(s); i++{
fmt.Printf("% x", s[i])
}
- ã²ãšã€ã®æåã¯è€æ°byteã§è¡šçŸãããå¯èœæ§ããããæåãè¡šãbyteããŸãšããŠèªãŸãªããšæ£ããæåãšããŠèªèã§ããªããªã
- ãªã®ã§æåãæ°ããåäœãšããŠã¯byteã§ã¯ãªãcode pointã®ã»ããéœåããããGoã§ã¯code pointãåäœãšããŠæåãæ±ãããã®ä»çµã¿ãã€ãŸãruneãçšæããŠãã
- runeã®å®äœã¯int32ã®ãšã€ãªã¢ã¹ãint32ãªã®ã¯Unicodeã®4byteåã®code pointãè¡šçŸãããã
https://github.com/kd-collective/go/blob/9b8750f53ed89fb326e4d811524e647683136bac/src/builtin/builtin.go#L90-L92
fmt.Println('ã')
fmt.Println('a')
fmt.Println(' ')
fmt.Println('!')
fmt.Println('"')
fmt.Println('a' * 2)
fmt.Println('a' - 'b')
s := "ããã"
fmt.Println([]rune(s))
fmt.Println([]byte(s))
ã€ãã³ãã«ãŒããªãã§ã®ãã€ããã©ãŒãã³ã¹ â C10Kåé¡ãžã®Goã®åç | POSTD
Goã«ãŒãã³ã®è§£èª¬ãããŒã¹ããªãã®ã§ããç解ã§ããªãã£ãã
Goã«ãŒãã³ã®è§£èª¬ãããããããªãã£ãã
éåæåŠçã®è§£èª¬ãGoã®ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®è§£èª¬èšäºã
Goã®ããã©ãŒãã³ã¹æé©ã®èªã¿ç©ã
Goã®iotaã®Tipsã
Goã¢ã»ã³ããªã®è§£èª¬èšäºãGoã®å éšä»æ§ã«ã€ããŠã®æ¬ã
Goã¢ã»ã³ããªã®è§£èª¬ãpackage main
func add(a, b int32) (int32, bool) { return a + b, true }
func main() { add(10, 32) }
Mapã®äžèº«ã®è§£èª¬ã
Reproducible Builds â a set of software development practices that create an independently-verifiable path from source to binary code
åçŸå¯èœãªãã«ãã
[[https://zenn.dev/nobishii/articles/goquiz_20230817][[Go Quiz] åäžã®åã®ã¿ã«ããåå¶çŽãæã€åãã©ã¡ãŒã¿ãåã«æã€å€æ°ã«ãã®åã®å€æ°ãä»£å ¥ã§ããã]]
åã®ã¯ã€ãºã
ãžã§ããªã¯ã¹ã®è§£èª¬ã
Untyped Constantsã®è§£èª¬ã
iotaã§äœãã®ãããã©ã«ãã§ã¯ããããã©ã
[[https://www.oreilly.com/library/view/hands-on-software-architecture/9781788622592/][Hands-On Software Architecture with Golang [Book]]]
Golangã®æ¬ã
ã·ã³ã¿ãã¯ã¹ã®æå³ã
Goã®æŽæ°ã®ä»æ§ã®è§£èª¬ã
go buildã®ä»çµã¿è§£èª¬ãå šç¶ããããã
Goã®èšèªãã¶ã€ã³ã®è§£èª¬ã
Russ Coxã«ããã€ã³ã¿ãŒãã§ãŒã¹ã®è©³ãã解説ã
golangã®äžŠè¡åŠçã®ããã®èšèªèŠçŽ ã«å¯Ÿå¿ããCSPã®èšè¿°ãç解ããŠåœ¢åŒæ€èšŒã®å®è·µãéå§ããã(èšè¿°ç·šïŒ - Qiita
CSPãç解ããã
Cã®ã·ã³ã¿ãã¯ã¹ãšã®éããçç±ã
å ¬åŒããã¥ã¡ã³ãã®ç¿»èš³ã
Goèšèªäœã¬ã€ã€ãŒå ¥é Hello world ã ç»é¢ã«è¡šç€ºããããŸã§ (GoConforenceTokyo2021) - Google Slides
Goã¢ã»ã³ãã©ã®è§£èª¬ã
go buildã®ä»çµã¿ãå®éã«åãããŠåã£æãããèŠã€ããã®ãé¢çœããããããã¢ãããŒããããã®ãã
ç§ã¯ãœãŒã¹ãèªãããããªããŒã¹ãšã³ãžãã¢ãªã³ã°ããæ¹ãåŸæãªã®ã§ãä»åããã°ã ããèŠãŠåŠçå 容ãæšæž¬ããŠèªäœããŸããã
ãã«ãã¿ã°ã§èšåãããŠãããŒãžã
- Goã®ãã«ãã¿ã°ã®æžãæ¹ã// +buildãã//go:buildã«å€ãã£ãçç±
Go Docã®ã³ã¡ã³ãã®ä»æ§ã
ã³ã³ãã€ã©ã®æé©åã
Goãšã¹ã±ãŒãã®èª¬æã
Profile-Guided Optimizationã¯ãã³ã³ãã€ã«ææé©åã®ãã³ããšããŠãã©ã³ã¿ã€ã ã®ãããã¡ã€ã«æ å ±ã䜿ãããšã§ããå¹çããæé©åããææ³ã§ãã
Goã§ã¹ã¬ããïŒgoroutineïŒã»ãŒããªããã°ã©ã ãæžãããã«å¿ ã泚æããªããã°ãããªãç¹ - Qiita
䞊åå®è¡ã®æ³šæç¹ã
Goã®ã¡ã¢ãªã¢ãã«ã
sync.Onceã®ä»çµã¿ã
ãã£ãã«ã®ç¢å°ããªããšãã«ãããã±ãŒãžããªããšã©ãŒã«ãªãããšããããã¡ãããšãã£ã¡ã瀺ããŠã»ããã®ã«ããã©ãŒããã¿ãšãã«ãã®æ€ç¥ãåã£ãŠãªãããã«èµ·ããããã«èŠããã
å ¬åŒã®èšäºã
ã³ã³ãã€ã«æã«ãªã«ãèµ·ããŠãããããã°ãã調ã¹ãã
GCã®è§£èª¬ã
Goã®ã©ã³ã¿ã€ã ã®è§£èª¬ã
èšèªåŠçç³»ã®äœãæ¹ã
Goã³ã³ãã€ã«ã®æµãã
ãã³ãããŒã¯ããæ¹æ³ã
ãšã©ãŒãã³ããªã³ã°ã®æ¬ã
ãã€ã¯è€éãªå®æ°ã[[https://zenn.dev/senk/articles/33c9dc7ea25dab][[Go] èšèªä»æ§æžã®ãåãšå€ã®ç¹æ§ããç解ãã]]
å€ã
ã©ããããã ã£ãã
äŸã§åŠã¶è§£èª¬ã
nil == nil ã§ãªããšãïŒãŸã㯠Go ããã°ã©ãã¯æ¯ãããããã«äŸåãæ³šå ¥ããïŒ
çŽæã«åããæåããããããå éšã®ä»çµã¿ã®è©±ã
æ¥æçºå£²ãããæ¬ã
æ¥æ¬èªèš³ã
æ¥æ¬èªèš³ãããå ¬åŒããã¥ã¡ã³ãã
䞊è¡åŠçã®è§£èª¬æ¬ã䞊è¡åŠçãšäžŠååŠçã¯å šãç°ãªãã
- 䞊è¡åŠç(Concurrency)
- ããæç¹ã®ç¯å²ã«ãããŠãè€æ°ã®ã¿ã¹ã¯ãæ±ãããš
- ã©ããã颚ã«ãµãã€ãçµãããããã¯èªç±
- è€æ°ã®åŠçãç¬ç«ã«å®è¡ã§ãã æ§æ ã®ããš
- ã䞊è¡åŠçã§ããèšåãããã
- äžåºŠã«å€ãã®ããšãæ±ãããš
- åé¡è§£æ±ºã®æ段ãšããŠã®ããã°ã©ãã³ã°ãã¿ãŒã³
- å¹³è¡æ§ã¯ã³ãŒãã®æ§è³ª
- 䞊ååŠç(Parallelism)
- ããæç¹ã®ç¹ã«ãããŠãè€æ°ã®ã¿ã¹ã¯ãæ±ãããš
- 1ç¹ã«ãããŠãã¿ã¹ã¯AãšBãåæã«å®è¡ãã
- è€æ°ã®åŠçãåæã« å®è¡ ããããš
- ã䞊ååŠçã§çç£ããã
- äžåºŠã«å€ãã®ããšãè¡ãããš
- 䞊è¡åŠçãå¯èœã«ããããŒããŠã§ã¢ã®ç¹æ§ã®ããš
- 䞊åæ§ã¯åäœããŠããããã°ã©ã ã®æ§è³ª
ãã£ãã«ã¯éåä¿¡ãå®è¡åæã®ããã®æ©æ§ã
- ãŽã«ãŒãã³ã¯ä»ã®ã³ãŒãã«å¯ŸããŠäžŠè¡ã«å®è¡ããŠããé¢æ°ã®ããš(å¿ ããã䞊åã§ã¯ãªã)
Goã®ãã³ãºãªã³éã
IdãIDã«å€æããäŸã
èªãã
Goãããæžãããã®tipsã
Goã§åœ¹ç«ã€ãã¿ãŒã³ã
bufioã®ãããããã解説ã
TCPã®ä»çµã¿ãäœãæ¹ã
ã©ã¡ãã倧ãŸãã«ã¯åæåãããã®ã ãã埮åŠã«ç°ãªãã
- newã¯ãŒãå€ã§ç¢ºä¿ãããå€ãžã®ãã€ã³ã¿ãåŸãé¢æ°
https://github.com/kd-collective/go/blob/9b8750f53ed89fb326e4d811524e647683136bac/src/builtin/builtin.go#L212
- makeã¯ããããã¹ã©ã€ã¹ããã£ã³ãã«ïŒmap[type]type, []type, chanïŒã®ç¢ºä¿ãšåæåãè¡ãåãã®ãã®ãåŸãé¢æ°
https://github.com/kd-collective/go/blob/9b8750f53ed89fb326e4d811524e647683136bac/src/builtin/builtin.go#L207
ã¹ã©ã€ã¹ãªã©ã®é·ãã調ã¹ãLen()ã¯ã©ãããå®è£
ã«ãªã£ãŠããã®ã ããããçµã¿èŸŒã¿ã ãããã»ãã®é¢æ°ãšã¯ç°ãªãããã
https://github.com/kd-collective/go/blob/9b8750f53ed89fb326e4d811524e647683136bac/src/builtin/builtin.go#L161-L173
contextã®è©³ãã解説ããã®äººããããªãã
- contextã®valueã«å
¥ããã®ã«ãµããããå€ã¯ãªã¯ãšã¹ãã¹ã³ãŒããªå€
- 1ã€ã®ãªã¯ãšã¹ããåŠçãããŠããéã«å ±æããã
- ãŠãŒã¶ãŒID
- èªèšŒããŒã¯ã³
- ãã¬ãŒã¹ã®ããã«ãµãŒãåŽã§ã€ããåŠçID
ããŒãµã®ç解ãæ·±ããããã«ããã
åèã
æçµçã«ãã©ãŒããã¿ã«ãããã
- è€æ°è¡ã§ç¶ç¶ãããã®ãšãè¡å ã ãã§æå¹åããããã®ããããåºæ¬çã«è¡å
- å é è¡ã§å¹æãçºæ®ãããã®ãšãå²ãããšã§æå¹åãããã®ããã
Goã§ã€ã³ã¿ããªã¿ãæžãæ¬ã®ç¶ç·šã
Go Web ããã°ã©ãã³ã°ã
ããã°ã©ãã³ã°èšèª Go ããã¥ã¡ã³ã â ããã°ã©ãã³ã°èšèª Go ããã¥ã¡ã³ã v0.1 documentation
Goããã¥ã¡ã³ãã
Goã®Tipséã
èšèªä»æ§ã®æ¥æ¬èªèš³ããŽã«ãŒãã³ã®è§£èª¬ã
typeãšstructã®éãã®è§£èª¬ã
GitHub Actionsã§ããã«å®è¡ã§ããããã«ããã
- workflowåãã
- ã¹ã¿ãŒã¿ãŒããã±ãŒãžãäœæãã
ãã©ãŒã¯ãã©ãæ±ããåé¡ããããèªåã¯éçšã§ã«ããŒããŠããã©ãèªåã§äœ¿ãã«ã¯ååã ãã©ãä»ã®äººã«å©çšããŠãããã«ã¯ãŸã ããã§ãŒã
mainã䜿ã£ãŠãã®ã§ãããŒãžã§ã³ãåºå®ããŠå®å šã«äœ¿ããããã«ããã
READMEã®ã¿ã°ãmainã«ããŠãã®ã§ãããŒãžã§ã³çªå·ã«ãããã¿ã°ãåãæ¿ãããšç»åãå€ããããã«ããŠãå®å šã«ãããå®å¿ããŠäœ¿ããããã«ããã
èªã¿ããã©ã€ãã©ãªãmoduleã§ãçŽæ¥å®è¡ã§ããªããå®è¡ã§ããªããšãprintãããã°ãã§ããªãããã¹ãã§ãã§ããããã ãåŒæ°ãé¢åãªã®ã ãšå€§å€ã
ããŒã«ã«importã®æ¹æ³ãäžå¿ç¥ã£ãŠããããã
äœãäœã£ãŠããŠåèã«ãããšãã¯ãããèªãããç解ã§ãããã倧éæãªã¹ã³ãŒãã§ãç解ããããã§ãããšããŸãé²ãŸãªãã
goclocã¯ãªããžããªã®ã³ãŒãéã調ã¹ãããŒã«ãåèã«ãªããšããã®ã¡ã¢ã
- æ°è»œã«ã³ãã³ãå®è¡ã§ããããã«dockerã€ã¡ãŒãžãçšæãã
- ãªãã·ã§ã³ã®åãåãæ¹ãæ§é äœã«å ¥ããŠãã
- çµæãæ§é äœã«å ¥ããŠãã
- æ¬äœãšCLIã¯å¥packageã«ãªã£ãŠãã
æ°ã«ãªãéšåã
- èšèªå€å®ã®ã©ã€ãã©ãªã䜿ã£ãŠããã¿ããã ãã倧ããªãå²ãšéãªãããããã
CLIã«è²ãã€ããã©ã€ãã©ãªã
å¥ã®è²é¢ä¿ã®ã©ã€ãã©ãªãåºãŠãããäœãéãã®ãããããªãã
https://github.com/kd-collective/color/blob/dbae876e45b9c53e464d101d63f4758c9f0bd8e8/color.go#L131-L137
https://github.com/kd-collective/color/blob/dbae876e45b9c53e464d101d63f4758c9f0bd8e8/color.go#L149-L157
ãªãã ãå°å³ã«é·ãããããããããªãã
Goèšèªreflectãã³ããã㯠(æè¡ã®æ³ã·ãªãŒãºïŒNextPublishingïŒ) | åè 倧äºé | å·¥åŠ | Kindleã¹ã㢠| Amazon
reflectã®è§£èª¬ã
GoãšSAMã§åŠã¶AWS Lambda (æè¡ã®æ³ã·ãªãŒãºïŒNextPublishingïŒ) | æç° å¯¿æ² | å·¥åŠ | Kindleã¹ã㢠| Amazon
- 57
- Coffmanæ¡ä»¶
- ãããããã¯ãçºçããããã«ååšããªããã°ãªããªãæ¡ä»¶
- çžäºæä»
- ãã䞊è¡ããã»ã¹ããªãœãŒã¹ã«å¯ŸããŠæä»çãªæš©å©ãã©ã®æç¹ã«ãããŠãä¿æããŠãã
- æ¡ä»¶åŸ
ã¡
- ãã䞊è¡ããã»ã¹ã¯ãªãœãŒã¹ã®ä¿æãšè¿œå ã®ãªãœãŒã¹åŸ ã¡ãåæã«è¡ããªããã°ãªããªã
- 暪åãäžå¯
- ãã䞊è¡ããã»ã¹ã«ãã£ãŠä¿æãããŠãããªãœãŒã¹ã¯ããã®ããã»ã¹ã«ãã£ãŠã®ã¿è§£æŸããã
- 埪ç°åŸ
ã¡
- ãã䞊è¡ããã»ã¹(P1)ã¯ãä»ã®é£ãªã£ãŠãã䞊è¡ããã»ã¹(P2)ãåŸ ããªããã°ãªããªãããããŠP2ã¯P1ãåŸ ã£ãŠãã
- çžäºæä»
- ãããŠãã®èšèªã¯CSPã®ã¡ãã»ãŒãžããã·ã³ã°åœ¢åŒãããã¡ã¢ãªãå ±æãåæããã»ãã奜ãã§ãããå ±æã¡ã¢ãªã®ã¢ãã«ã¯æ£ç¢ºã«äœ¿ãããšãé£ãããªã
- Goã§ã¯ã¯ããããCSPãå°å ¥ããŠãã
- syncããã±ãŒãžã¯äŒçµ±çãªã¡ã¢ãªã¢ã¯ã»ã¹åæã§äžŠè¡åŠçãéæãããåé¡è§£æ±ºããå¹³è¡åŠçã®æžãæ¹ãé«æ°Žæº(Goã«ãŒãã³ããã£ãã«)ãäœæ°Žæº(sync)ã§éžæã§ãã
- ããã°ã©ã ãæžãéã«ã¯ããç¬éã«ãã 1ã€ã®ãŽã«ãŒãã³ãããç¹å®ã®ããŒã¿ã®è²¬ä»»ãæã€ããã«å¿ããããã¡ã¢ãªãå ±æããããšã§éä¿¡ããŠã¯ãããªãããããã«éä¿¡ããããšã§ã¡ã¢ãªãå ±æãã
- Goã®ã¢ãããŒãéä¿¡ã«ãã£ãŠã¡ã¢ãªãå ±æããã¡ã¢ãªã®å ±æã«ãã£ãŠéä¿¡ããŠã¯ãããªãã
- äœãããçµæãçæããã³ãŒããããããã®çµæãå¥ã®ã³ãŒãã«å
±æãããå Žåãããã¯ããŒã¿ã®æææš©ã移åããŠããããšã«ãªããã¬ããŒãžã³ã¬ã¯ã·ã§ã³ããµããŒãããŠããªãèšèªã§ã®ã¡ã¢ãªã®æææš©ãšåãèãæ¹ãããŒã¿ã«ã¯æææš©ããããå¹³è¡ããã°ã©ã ãå®å
šã«ããæ¹æ³ã®1ã€ãšããŠã1床ã«1ã€ã®äžŠè¡åŠçã®ã³ã³ããã¹ãã®ã¿ãããŒã¿ã®æææš©ãæã€ããã«ããããã£ãã«ã䜿ããšããã®æå³ããã£ãã«ã®åœ¢ã§è¡šçŸããããšã§äžŠè¡ããã°ã©ã ãå®å
šã«ããæ§æ³ãäŒããããšãã§ãã
- 倧ããªå©ç¹ã¯ããããã¡ä»ããã£ãã«ãçæããŠãã³ã¹ããäœãã€ã³ã¡ã¢ãªã®ãã¥ãŒãå®è£ ãçç£è (Producer)ãšæ¶è²»è (Consumer)ãåãé¢ãããšãã§ãã
- OSã¹ã¬ããã䜿ãèšèªã§ã¯å¹³è¡åŠçãæœè±¡åããæ¹æ³ãšããŠäŸ¿å©ãªã»ãã®ãã¿ãŒã³ãå®è£ æ¹æ³ããããããšãã°ã¹ã¬ããããŒã«ãããããæœè±¡åã¯ãããŠãOSã¹ã¬ããã®è£åŒ·ã匷åãããç®çã§äœãããŠããŠãGoã§äœ¿ãããšã¯ããŸããªã
- åé¡ç©ºéããŽã«ãŒãã³ã«åœãŠã¯ããããããã«ããŠãã¯ãŒã¯ãããŒå ã®äžŠè¡åŠçéšåãããŸãè¡šçŸããã©ãã©ããŽã«ãŒãã³ãèµ·åãã
- ãŽã«ãŒãã³
- ä»ã®ã³ãŒãã«å¯ŸããŠäžŠè¡ã«å®è¡ããŠããé¢æ°ã®ããš(å¿ ããã䞊åã§ã¯ãªã)
- ãŽã«ãŒãã³ã¯ã³ã«ãŒãã³ãšããŠç¥ãããé«æ°Žæºã®æœè±¡å
Goèšèªã«ããåæ£ãµãŒãã¹ âä¿¡é Œæ§ãæ¡åŒµæ§ãä¿å®æ§ã®é«ãã·ã¹ãã ã®æ§ç¯ | Travis Jeffery, æŽç° è³æš¹ |æ¬ | é販 | Amazon
åæ£ãµãŒãã¹ã®è§£èª¬ã
å®çš Goèšèª âã·ã¹ãã éçºã®çŸå Žã§ç¥ã£ãŠããããã¢ããã€ã¹ | æžå· ããã, 蟻 倧å¿é, çé éŒèš |æ¬ | é販 | Amazon
- 45, 94, 102, 199, 232
æ¥åã«åœ¹ç«ã€Goã®è§£èª¬ã
Javaã®äžçã§ã¯ã芪ã®ã³ã³ãããŒã«ã¯ã©ã¹ãç¶æ¿ããŠå¿ èŠãªã¡ãœãããåå®çŸ©ããã¬ãŒã ã¯ãŒã¯ããå©çšããããšãã£ã倧èŠæš¡ãªãã¬ãŒã ã¯ãŒã¯é¢šã®ã³ãŒãã£ã³ã°ã¹ã¿ã€ã«ããããŸããããã¯main()é¢æ°ãèŠããªãããããªãŠããã®æ³åãã«ã®ã£ãšã£ããã®ã§ãäžèŠã³ãŒãéãå°ãªãå¹çãè¯ãããã«æããŸããããã¬ãŒã ã¯ãŒã¯ã®é²åãé²ãã°é²ãã»ã©ããœãããŠã§ã¢ã®æ§é ãèããŠå®è£ ãããšããçµéšãåŸããããããœãããŠã§ã¢ã®ä»çµã¿ãéçºæè¡ãåŠã¶ããããããã¬ãŒã ã¯ãŒã¯ã®äœæ³ããåŠã¶ããšãèŠæ±ãããããã«ãªããŸãããžã¥ãã¢ãªéçºè ã§ãã¬ãŒã«ããå€ããããšãªããäžå®ã®ææãããããããšããå©ç¹ããããŸãããããã°ã©ããŒãšããŠã®æé·ãé£ãããšããæ¬ ç¹ããããŸãã
- Goã§ããã©ãŒãã³ã¹ã«å·®ããããããã¡ãªãã€ã³ãã¯ã¹ã©ã€ã¹ãšãããã®ã¡ã¢ãªç¢ºä¿
- ã¹ã©ã€ã¹ã¯ãã®å®æ ãšããŠåºå®é·ã®é åã確ä¿ãããŠãããã¹ã©ã€ã¹ã¯ãããåç §ããçªãšããŠäœ¿ããã¡ã¢ãªã®èªã¿æžããè¡ããã
- é·ãã足ããªããšãã£ãŠå¥œãåæã«æ¡åŒµã§ããªã
- è£ã®é åã«èŠçŽ ãè¿œå ãç¶ããŠå²ãåœãŠããããµã€ãºã䜿ãæãããå ŽåãGoã®ã©ã³ã¿ã€ã ã¯æ°ããã¡ã¢ãªã確ä¿ããããã«é åã®å 容ãã³ããŒããŠç§»åãã
- 確ä¿ããŠããã¡ã¢ãªã®ããšããã£ãã·ãã£ãšãããcap()ã§ååŸã§ãã
- ãªãŒããŒã©ã€ãã»ç¶æ¿ã®ãããªããžã§ã¯ãæåããã°ã©ãã³ã°ã§ã¯ãã³ãã¬ãŒãã¡ãœãããã¿ãŒã³ãäžè¬çã«çšãããã
- ãã³ãã¬ãŒãã¡ãœãããã¿ãŒã³: ãã¬ãŒã ã¯ãŒã¯åŽã§ããžãã¯ã®å€§éšåãã«ãªããäžéšã®ã«ã¹ã¿ãã€ãºå¯èœãªãã€ã³ãã®ããžãã¯ã®ã¿ãå€æŽããèšèš
- Goã§ã¯ãã³ãã¬ãŒãã¡ãœãããã¿ãŒã³ã䜿çšããªã代ããã«ã¹ãã©ããžãŒãã¿ãŒã³ãçšãã
- ã·ã³ãã«ãªã€ã³ã¿ãŒãã§ãŒã¹ã䜿ãAPI(Reader, WriterãåŒæ°ã«ãšã)ãã³ã¢ãšããŠäœãããããã©ããããŠäœ¿ããããAPIãå¥ã«æäŸããã®ããGoã§åºãè¡ãããŠããèšèšæ¹æ³
- ãŠããããã¹ããªã©ãè¡ããããã
- ææ³ãã·ã³ãã«ã ãããããã©ã䜿ãããéèŠã«ãªã£ãŠãã
- ãšã©ãŒã®ã©ãããã¢ã³ã©ãããã§ãããããšãã°ããã¡ã€ã«ãã¹ãšã©ãŒããšããäœã¬ãã«ãªãšã©ãŒãã©ããããŠãèšå®ãã¡ã€ã«ã®èªã¿èŸŒã¿ãšã©ãŒããšããæœè±¡åºŠã®é«ããšã©ãŒã§è¡šçŸã§ããå¿ èŠã«å¿ããŠã¢ã³ã©ãããã詳现æ å ±ã«ãã¢ã¯ã»ã¹ã§ãã
- ãšã©ãŒã®ãã§ãã¯å¿ããkisielk/errcheckã§ç¢ºããããã
go install
ã¯go.modã«åœ±é¿ãªãã€ã³ã¹ããŒã«ã§ãããgo get
ã¯go.modã«åæ ãã- Goã®å Žåãããã±ãŒãžãçžäºäŸåã®é¢ä¿ã«ã§ããªãããšãããããã±ãŒãžé£æºããšã«åããããªæ§é äœãéç£ããããšã«ãªãã³ãŒãéãå¢å ããããŸãã¯ã·ã³ãã«ã«ãããã±ãŒãžã现ããåå²ããªãããšãèãã
- ãã©ãŒã¯ããGoãããžã§ã¯ãã¯ããã·ã¥ãç°ãªãããããã®ãŸãŸã§ã¯äŸåé¢ä¿ã«èšè¿°ã§ããªã
ç°¡åãªã²ãŒã ã®ãã¥ãŒããªã¢ã«ã
ã²ãŒã ã®ãã¥ãŒããªã¢ã«ã
Ebitenã§ããŒã°ã©ã€ã¯ãäœããã¥ãŒããªã¢ã«ã
Ebitenã®å°ããªãã¥ãŒããªã¢ã«ã
ãšãã¥ã¬ãŒã¿ã®äœãæ¹ã®æŠèŠãäœãæ¹ã®è§£èª¬ã
ããã¹ã¿ããªãã£ã®é«ãGoã®APIãµãŒããéçºãããããšãããã³ãºãªã³ãå ¬éããŸãã - DeNA Testing Blog
Goã®APIãã³ãºãªã³ã
Dockerã³ãŒãã®æŠç¥ã
ãµãŒãåŽGo, ã¯ã©ã€ã¢ã³ãåŽRubyãšç°ãªãèšèªãçšããŠãµã³ãã«ã¢ããªã±ãŒã·ã§ã³ãå®è£ ããã
ãããããããšããå ¥éæžãGoããã°ã©ãã³ã°å®è·µå ¥é æšæºã©ã€ãã©ãªã§ãŒãããWebã¢ããªãäœããå§èšã - é人åºçäŒ
- 27, 68, 73, 93, 148
ãŒãããå®è£ ãããããŸããã³ãšããªãã
- ãã¬ãŒã ã¯ãŒã¯ã䜿ãã°ããæ§ç¯ã§ããããããã¬ãŒã ã¯ãŒã¯ç¬èªã®çŽæäºããã¿ãŒã³ã«åŸããªããšãããªãããšãå€ããããããã¹ããã©ã¯ãã£ã¹ã§ãããšä»®å®ããŠãããããã¹ããã©ã¯ãã£ã¹ã¯ç解ããŠããªããšã«ãŒãŽã«ã«ãã»ããã°ã©ãã³ã°ã«é¥ãã©ããªãšãã§ãç¡æ¡ä»¶ã§é©çšããŠããŸã
- ãã¬ãŒã ã¯ãŒã¯ãæ§ç¯ããåºç€ãšãªã£ãŠããæŠå¿µãç解ããããšãéèŠãæ£ããç解ãããã°ãããçŽæäºããã¿ãŒã³ãååšããçç±ããããããã«ãªã
- ããšãã°ã¯ã©ã€ã¢ã³ãåŽã«ã¯ãããŒãšããŠããŒã¿ãä¿æãããµãŒãåŽã«ã»ãã·ã§ã³ãšããŠä¿æããã®ã«ã¯çç±ããããHTTPãã³ãã¯ã·ã§ã³ã¬ã¹ã®ãããã³ã«ã§ããããµãŒãã®ååã®åŒã³åºãã«ã¯ä»¥åã®åŒã³åºãã®æ å ±ãå«ãŸããŠããªãããã§ãã
- Goèšèªã«ãããŠãã³ãã©ãšã¯ãServeHttpãšããã¡ãœãããæã£ãã€ã³ã¿ãŒãã§ãŒã¹ã®ããš
- ãGoããã«ããã¬ã¯ãµã£ãŠãªãããã - Qiita
Mastering Go Create Golang production applications using network libraries, concurrency, and advanced Go data structures
å®éã®åèã«ãªã䜿çšäŸã
Goã®ã³ã³ãã€ã©ã®è§£èª¬ã
é¢çœãããã«ãªãé¡æã®çŽ¹ä»ã
èªã¿æ¹ãããæ·±ãç解ã®ããããã
GoSpecã¯èšèªä»æ§æžã§ãããå šãŠã®èšè¿°ã«ã¯æå³ãããã¯ãã§ãã
äŸãã°Typesã®ç« ã§å°å ¥ããããå šãŠã®åã«ã¯underlying typeãããããšããæŠå¿µã¯ãäžèŠãããšããªãã§ãããªãã®ãå°å ¥ãããã ïŒïŒããšæããããããŸããã
(ç¥)
ãããããã®underlying typeã¯assignability(ä»£å ¥å¯èœæ§)ãå®çŸ©ããããã«äžå¯æ¬ ãªãã®ã§ã(åŸè¿°)ã
ãã®ããã«ããã®èšè¿°ã¯ã©ãã§åœ¹ã«ç«ã€ã®ïŒããšããæèãæã€ããšã§ãå šäœåã®ç解ã«ã€ãªãããŸãã
ææžç±ã«ãäŸç€ºã¯ç解ã®è©Šéç³ããšããèšèããããŸãã
(ç¥)
ããã¯æ¬åœã«ããã§ãèªãã å 容ãå ã«ãããããã³ãŒãã¯ãã®èšè¿°ãå ã«ç¢ºãã«ããããæåãããããšããäŸãäœãããã©ããã§ç解ã®æ·±ãã段éãã ãšããå®æããããŸãã
invoke_virtualã®ã¡ãœããåŒã³åºãã§è©°ãŸã£ãŠããã
ãã®ãžããåèã«ãªãããé¢æ°ãªããžã§ã¯ããããã·ã¥ã«å ¥ããŠãããŠãæ€çŽ¢ããŠåŒã³åºãã°ããã
Goã®ã³ã³ããªãã¥ãŒã·ã§ã³ã¬ã€ããGoã«ã³ã³ããªãã¥ãŒããããã¥ãŒããªã¢ã«ãéçºç°å¢æ§ç¯ãGoogleã®èŠçŽãžã®ãµã€ã³ãå€æŽãã¬ãã¥ãŒãŸã§ã®æµããå šãŠã«ããŒããŠãããããããããã
- 388fbf287c
æ¯æ¥ããããã®ã³ãããããããã©ããã£ãããšããã£ãŠãããè¯ãããŠããã®ã ããããã³ãŒãã®çš®é¡ãè°è«ã®é²ãæ¹ããã¡ã€ã«ãèŠãŠã€ãããç解ããŠããã®ã¯é£ããããå·®åããå°ããã€èŠãŠããã°ç³žå£ãã€ãããã®ã§ã¯ãªããããŸããããã°ã©ãã³ã°èšèªã®å Žåãã©ã€ãã©ãªã§ãå šç¶éãã¯ããªã®ã§èª¿ã¹ãã
éçºåå ã«å¿ èŠãªæ®µéãšããŠãã³ãŒããšããããåšèŸºç¥èãã€ããã°ããããã«èŠããã
- æªäœ¿çšã³ãŒãåé€
- contextãªãã·ã§ã³è¿œå
- ãªãŒããŒãããŒãé²ãããuintåãž
- ç»åå€æã®é«éå
- ç¹å®ã®æ¡ä»¶ã§vendorã¢ãŒãã«å ¥ãã®ãé²ã
- cmd.StdinPipe()ã䜿ã£ãŠãã¹ãã®sleepãã«ããŒãæ¶ã
- ç¹å®ã®ãã¹ã倱ææã®ãããã°æ å ±ãå¢ãã
- ã¡ã¢ãªå¹çã®è¯ãã³ãŒãã«çœ®ãæãã
- OSããšã«ç°ãªãéšåã®äžéšãä¿®æ£ãã
- ãã¬ãŒããŒãã¹ããä¿®æ£ãã
- ãã¹ãã®ã«ããŒããŠãªãéšåãè¿œå ãã
- ãšã©ãŒæã®æå
- æå³ã®ãªãäžéå€æ°ã®åé€
- ãšã©ãŒã³ãŒãã®ä¿®æ£
- ãšã©ãŒã³ãŒãã®å ±éå
- å€æ°åã®ä¿®æ£
- ããã¥ã¡ã³ãã®ä¿®æ£
- Plan9ã§ã®ããã¡ã€ã«äžŠåã¢ã¯ã»ã¹
- ããŒãžã§ã³ã«ãã£ãŠç°ãªãæåéšåã®ãšã©ãŒã«ã€ããŠãã¡ãã»ãŒãžã«ããŒãžã§ã³æ å ±ãè¿œå
- ãã¹ãã䞊åã«ãã
- äžèŠã«ãªã£ããã¹ãã®åé€
- ç¡éã«ãŒãã«ãªã£ãŠã¿ã€ã ã¢ãŠãããåé¡ã®ä¿®æ£
- 䟿å©é¢æ°ã䜿ã(strings.Cut) 2e054128bf
- tarã®ããããŒã«ãã¡ã€ã«ãµã€ãºå¶éãã€ãã 0bf7ee9977
ãããã£ãŠåæããŠã¿ããšãå€ãã®é åãã«ããŒããå¿ èŠã¯ãªãããšãããããåãçµã¿ããããšããããéäžçã«ããé åã決ããã°ããããã
issueãèŠãŠã¿ããããããããŸã解ããã°æ¥œãªã®ã ããçš®é¡ãä»ã®æ®µéã§ããããããªããŠããè°è«ãèŠãããšã¯èª¿ã¹ãåã£æããã«ãªããããäœãç解ããããšããŽãŒã«ã«ãªãã®ãããšããããšã ãæ£æŒ«ã«èªããããããåé¡ãããããšã念é ã«ãããŠãä»çµã¿ãç¥ãããšããã»ããé ã«å ¥ãã解ãããã«å¿ èŠã ããã ã
- go fmtã®ãã°
- æ©èœãªã¯ãšã¹ã
- ãã¬ãŒããŒãã¹ã
ã¡ã¢ã
- çµéšè±å¯ãªããã°ã©ããŒãã©ããã£ãŠåé¡è§£æ±ºããŠãããã®çã®è³æã«ãªãã
- å šäœããµãããã§ã¯ãªããç¹å®ã®ã³ãã³ãã«çµã£ãŠç¥èãæ·±ãããåé¡ã«åãçµãã®ããããã
src/all.bash ã«ã·ã§ã«ã¹ã¯ãªããããããããã§ã³ã³ãã€ã«ã§ãããå®è¡ã«ã¯goãå¿ èŠãgoã䜿ã£ãŠgoãã³ã³ãã€ã«ããã
$ cd src # ã«ã¬ã³ããã£ã¬ã¯ããªãsrcäžã§ããå¿
èŠããã
$ ./all.bash
æå ã§ã³ã³ãã€ã«ããŠgoåŠçç³»ãææ°ã«ããŠãªãå Žåãâã®ãããªç¶æ ã«ãªãã
- ãã¹ããå®è¡ãããšããã±ãŒãžé¢é£ã§å€±æãã
- å®è¡ã§ãããã¹ãããããããœãŒã¹ã³ãŒã(æ¬äœããã¹ã)ãžã®å€æŽãå šãåæ ãããããã¹ãŠæåãã
ããã£ãŠãã¹ããèµ°ãããããã«ãããŠãåæ ããªããéåžžã§ããã°æ§æã¬ãã«ã«ãªããã®ãç¡èŠããããå¥ã®ãœãŒã¹ã³ãŒããèŠãŠãããœããæ¬äœã³ãŒãã«ã€ããŠã¯ã¯ãŒãã³ã°ãã£ã¬ã¯ããªã§ã¯ãªãããã·ã³ã«ã€ã³ã¹ããŒã«ããŠããgoã䜿ã£ãŠããæ°ããããªããã¹ããåæ ããªãã®ã¯ããããããªãã$ go test -v package std/math/big arith_amd64.go:10:8: use of internal package internal/cpu not allowed
- æå ãã«ãããææ°ã®goãžã®ãã¹ãéã£ãŠããªãããã ã£ãããã¹ãéããšããã¹ãã倱æãããããããã«
- ã©ãããŠãã¹ããåæ ãããªããšããçµæã«ãªãã®ãããããªã
䜿ããããªãåèã«ãªããããªã©ã€ãã©ãªããŸãšããã
cliã¢ããªãäœãã©ã€ãã©ãªã
Goã§CUIããŒã«ãäœããã©ã€ãã©ãªã
CLIã§Dockerã®ç¶æ ãé²èŠ§ã§ããã©ã€ãã©ãªã
[[https://qiita.com/hgsgtk/items/363c02064d25e73b03a4][[Go] constant x.x truncated to integerã¯ãªããããã®ã #Go - Qiita]]
å°æ°ãŸããã®è§£èª¬ã
Unixã©ã€ã¯ãªã€ã³ã¿ãŒãã§ãŒã¹ã«ããã¡ãªããã»ããæ¹ã
filepathã®æ¬ã
Goã®èªã¿ç©ãªã¹ãã
Goã®ãªããžããªãã¬ã³ãã
Goã®ååã«é¢ãã解説ãããèšãããããšãã ããæšæºã©ã€ãã©ãªãåèã«ãªããšæžããŠããã
Goã®ããã±ãŒãžæ§æãååãªã©ã®è§£èª¬ãå®éã®ãªããžããªãäžããŠããŠããããããã
ã¯ãªãŒã³ã¢ãŒããã¯ãã£ã®æ¬ã
ããã«ãŠã§ã¢ã§è¿ããã¬ã¹ãã³ã¹ãååŸããæ¹æ³ã
ãµãŒãèªäœã§APIããã¥ã¡ã³ããæäŸããæ¹æ³ã
openapi3filterã®äŸã
Goã«ãããµãŒãã¹éçº6幎ã®ãããã - Go Conference 2021 Autumn Sponsor Session | ãã€ãã¹æ ªåŒäŒç€Ÿ
ã¡ã¢ã
ã¢ãã¯ã極åããªãæµåã®ãå€å žåŠæŽŸã®ãã¹ãæ¬ã
Goã®æŽå²ã
çç±ãæžãããŠããã
MacOSã§ã® Go1.14ã®ã³ã³ãã€ã«ã«X Codeãå¿ èŠãªã®ã¯æå³çã§ãªãã£ãããã°ããã®éã誰ãããããã°ãšããŠæ°ã¥ããªãã£ãã
ã¿ãã®ããã¯ãšã³ããµãŒãã
GoReleaser 㧠Go 補 CLI ã®ãªãªãŒã¹ãèªååïŒ Homebrew ã§ã€ã³ã¹ããŒã«ã§ããããã«ãã
goreleaserã®äœ¿ãæ¹ã
ãããã°æ¹æ³ã®è§£èª¬ã
1.20ã®å€æŽãæ¯èŒå¯èœãªåã
GoããŒã«ãã§ã€ã³ã
go.modã§æå®ããããŒãžã§ã³ã§ã¯ãGoããŒã«ãã§ãŒã³ãæå®ããããã§ã¯ãªãããããå€ããããšããææ¡ã
cmd/go: âloadPackageData called with empty package pathâ build panic · Issue #60686 · golang/go
æ¯èŒçãããããããå°ããªãã°ã
randã®å®è£ ãå¹çãè¯ããã®ã«å€ããææ¡ã
go pluginã®äŸã
çŽ æ°ã«9ãå«ãŸããŠããã®ã¯ã¿ã€ãã§ã¯ãªãããããããžã§ãŒã¯ãšã®ããšã
é«å質ãªGoã®ãã¥ãŒããªã¢ã«ã
ããã»ãã€ã¯ã«ããGoã®ã¹ã©ã€ãã
Goã®ã¹ã±ãžã¥ãŒã©ãå®è£ ããã
ãããããã説æã
- go get ã¯go.modã«å€æŽãå ãã
- go install ã¯ãã€ããªãã€ã³ã¹ããŒã«ãã
ç¥ããªãã£ããªã
Go FridayããŒã話ïŒéå ¬éïŒunexportedïŒãªæ©èœã䜿ã£ããã¹ã #golang | ã¡ã«ã«ãªãšã³ãžãã¢ãªã³ã°
- ãããã¯ãã³ãŒããšãã¹ãã¯å¥ããã±ãŒãžããã»ãããã
- ã¯ãããŠã®ãŠãŒã¶ã«ãªããã€ã³ã¿ãŒãã§ãŒã¹ãå ¬éã®ç¶æ ãèãããããã
- éå ¬éãªé¢æ°ãå€æ°ããã¹ããããšãã¯ããã¹ãçšã«ãšã¯ã¹ããŒãããã°ãã
ãµãŒãã€çµæã
proposaläžèŠ§ã
Goèšèªã®proposalã
Goã§éç解æãããå ¥éæ¬ã
Goã®ASTãã¥ãŒã¯ãŒã
ãœãŒã¹ã³ãŒãã®åŒã³åºãé¢ä¿ãã°ã©ãã£ã«ã«ã«è¡šç€ºããã
XMLããGoã®æ§é äœã«å€æããããŒã«ã
Goããã°ã©ããŒãYoutuberããã£ã³ãã«ã¯æŽæ°æ¢ãŸã£ãŠããœãã
Goã®å ¬åŒããã°ã
å ¬åŒããã¥ã¡ã³ãã
åèã«ãªãissueããã°å ±åã®ããŸãããæ¹ãplaygroundã䜿ããã¿ã€ã ã¢ãŠãã«ãªããã°ã®åå ã
Emacsã®go-modeã§ã®ãã©ãŒããããå®çŸ©ãžã£ã³ãã䟿å©ãªããŸããŸãªæ©èœã
- C-c C-a ã§importãè¿œå ã§ãã
Goã«ãŒãã³ã®è§£èª¬ã
æ軜ã«äœ¿ããã
Goã®ã²ãŒã ã©ã€ãã©ãªã
ã¹ã©ã€ã¹ã®è©³ãã解説ããã£ãã·ãã£ã¯åç §ããã¡ã¢ãªé åã®ç¯å²ã
Goèšèªã楜ãã5ã€ã®ã¬ã·ã ã³ã¿ããšèæãšãŽãŒãã¡ãŒãšããããå§èšã - é人åºçäŒ
ãã£ãšèªãã ã ããã³ãŒãã®äžã¯èªãã§ãªãã®ã§å¿ èŠã«ãªã£ãã確èªããã
æåã®ãã¥ãŒããªã¢ã«ãå°ããªã³ãã³ãã©ã€ã³ããŒã«ã®äŸã
[[https://haibara-works.hatenablog.com/entry/2020/12/05/235227][Goã§Dockerãæã [Docker Engine SDK] - ã¯ãã°ãã®ããã°]]
- 117, 133, 141, 155
Goèšèªã®å ¥éæ¬ã
- Goã§ã¯ãæåã®æåã倧æåã§å§ãŸãååã¯ãå€éšã®ããã±ãŒãžããåç §ã§ãããšã¯ã¹ããŒããããååãäŸãã°Piã¯mathããã±ãŒãžã§ãšã¯ã¹ããŒãããã
package main
import (
"fmt"
"math"
)
func main() {
fmt.println(Math.pi)
}
- å€æ°ãååšããã¡ã¢ãªäžã®äœçœ®ããã¢ãã¬ã¹ããšããããã®ã¢ãã¬ã¹ãæ ŒçŽå¯èœãªå€æ°ãããã€ã³ã¿ããšãã
int
åå€æ°ã®ã¢ãã¬ã¹ãæ ŒçŽã§ãããã€ã³ã¿ã®åã¯*int
åãšããããã«ãã¢ã¹ã¿ãªã¹ã¯ãã€ãã
var ptr *int
var i int = 12345
ptr = &i
fmt.Println("iã®ã¢ãã¬ã¹:", &i)
fmt.Println("ptrã®å€(å€æ°iã®ã¢ãã¬ã¹):", ptr)
fmt.Println("iã®å€:", i)
fmt.Println("ãã€ã³ã¿çµç±ã®iã®å€:", *ptr)
*ptr = 999
fmt.Println("ãã€ã³ã¿çµç±ã§å€æŽããiã®å€:", i)
func main() {
a, b := 1, 1
double(a, &b)
fmt.Println("å€æž¡ã:", a)
fmt.Println("ãã€ã³ã¿æž¡ã:", b)
}
func double(x int, y *int) {
x = x * 2
*y = *y * 2
}
é¢æ°ãªãã©ã«ã
func main() {
val := 123
// é¢æ°ãªãã©ã«ã®èšè¿°ãšåŒã³åºããåæã«è¡ã
func(i int) {
// é¢æ°ãªãã©ã«å€ã®å€æ°valã«ã¢ã¯ã»ã¹å¯èœ
fmt.Println(i * val)
}(10)
// é¢æ°ãªãã©ã«ãå€æ°ã«ä»£å
¥
f := func(s string) {
fmt.Println(s)
}
f("hoge")
}
é¢æ°åã
func main() {
// é¢æ°åã®å€æ°å®£èš
var f func(int, int) int
// é¢æ°ãªãã©ã«ã®å€ã代å
¥
f = func(a int, b int) int {
return a + b
}
// é¢æ°åã®å€æ°çµç±ã§é¢æ°ãåŒã³åºã
fmt.Println(f(1, 2))
// é¢æ°åã®å€æ°ã«å€ã代å
¥
f = multiply
// é¢æ°åã®å€æ°çµç±ã§é¢æ°ãåŒã³åºã
fmt.Println(f(1, 2))
}
func multiply(x int, y int) int {
return x * y
}
ã¡ãœããã®å®£èšã
type myType int
// myTypeåãã¬ã·ãŒãã«æã€é¢æ°ãããªãã¡myTypeåã®ã¡ãœããã宣èšãã¬ã·ãŒãã¯äžçªæåã«æžã
func (value myType) println() {
fmt.Println(value)
}
func main() {
// myTypeåã®å€æ°ã宣èšãã
var z myType = 1234
// myTypeåã®ã¡ãœãããåŒã³åºã
z.println()
}
ã¡ãœããã®ã¬ã·ãŒãããã€ã³ã¿ã«ããã
// intå
type myType int
func (value myType) setByValue(newValue myType) {
// ããã§å€ã代å
¥ããŠãç¡æå³ãValueã¯ã³ããŒãããã®ã§
value = newValue
}
func(value *myType) setByPointer(newValue myType) {
// 代å
¥ããå€ãåæ ããã
*value = newValue
}
func main() {
var x myType = 0
// ã¬ã·ãŒãã¯å€ãå€ã¯å€æŽã§ããªã
x.setByValue(1)
fmt.Println("å€: 0 ->", x)
// ã¬ã·ãŒãã¯ãã€ã³ã¿ãå€ã¯å€æŽã§ãã
x.setByPointer(2)
fmt.Println("ãã€ã³ã¿: 0 ->", x)
}
æ§é äœåã«ååãã€ããã
type MyData struct {
s string
b byte
}
- ã¡ãœããã®å®£èšã«ã¯å€ã¬ã·ãŒãããã€ã³ã¿ã¬ã·ãŒãã®2ã€ããããæ··åšãããã¹ãã§ã¯ãªã
- å€æ°ã¬ã·ãŒãã§ã¯ã¡ãœããã®æäœã¯å ã®å€æ°ã®ã³ããŒãæäœãã
- ãã€ã³ã¿ã¬ã·ãŒãã§ã¯ããã€ã³ã¿ã䜿ãã®ã§å ã®å€æ°ãå€æŽã§ãã
- ãã€ã³ã¿ã¬ã·ãŒãã䜿ã2ã€ã®çç±
- ã¡ãœãããã¬ã·ãŒããæãå ã®å€æ°ãå€æŽãããã
- ã¡ãœããã®åŒã³åºãããšã«å€æ°ã®ã³ããŒãé¿ãããã
å¿åãã£ãŒã«ããå¿åãã£ãŒã«ããæã€ãã£ãŒã«ããšã¡ãœããããåã蟌ã¿å ã®æ§é äœåã«ãå®è£ ãããŠãããã®ããã«æ±ããããGoèšèªã«ã¯åã®å®è£ ã¯ãªãããæ§é äœã«ä»ã®åãåã蟌ãããšã§ç¶æ¿äŒŒããããªããšãå®çŸã§ããã
// åã蟌ãŸããåã®æ§é äœ
type embedded struct {
i int
}
// embeddedåã®ã¡ãœãã
func (x embedded) doSomething() {
fmt.Println("test.doSomething()")
}
// åã蟌ã¿å
ã®æ§é äœ
type test struct {
embedded // embeddedåã®åã蟌ã¿
}
func main() {
var x test
// embeddedåã«å®è£
ãããŠããã¡ãœããã«ãteståã®å€ã§ã¢ã¯ã»ã¹
x.doSomething()
// embeddedåã®ãã£ãŒã«ãã«ãteståã®å€ã§ã¢ã¯ã»ã¹
fmt.Println(x.i)
}
æ§é äœã®åæåã
type Person struct {
name string
age int
}
func main() {
// æ§é äœãªãã©ã«ã䜿çšããããã£ãŒã«ããåå¥ã«åæå
var p1 Person
p1.name = "Jhon"
p1.age = 23
// æ§é äœãªãã©ã«ã§åæå
p2 := Person{age: 31, name: "Tom"}
p3 := Person{"Jane", 42}
p4 := &Person{"Mike", 36}
fmt.Println(p1, p2, p3, p4)
}
åã蟌ã¿ãè¡ã£ãæ§é äœãæ§é äœãªãã©ã«ã§åæåããã
type Person struct {
name string
age int
}
type Employee struct {
id int
Person // åã蟌ã¿
}
func main() {
e := Employee{1, Person{"jack", 28}}
fmt.Println(e)
}
Goèšèªã®ã€ã³ã¿ãŒãã§ãŒã¹ã®åœ¹å²ã¯ãæ¯ãèãããèŠå®ããããšãGoèšèªã®ã€ã³ã¿ãŒãã§ãŒã¹ã¯ãã€ã³ã¿ãŒãã§ãŒã¹ããšããããå®è£ ããåããšã®é¢ä¿æ§ãæ瀺çã«èšè¿°ããå¿ èŠããªããã€ã³ã¿ãŒãã§ãŒã¹ã«å®çŸ©ãããŠããé¢æ°ãã¡ãœãããšããŠå®è£ ããŠããåã¯ãèªåçã«ãã®ã€ã³ã¿ãŒãã§ãŒã¹ãå®è£ ããŠããããšã«ãªãã
type Calculator interface {
// é¢æ°ã®å®çŸ©
Calculate(a int, b int) int
}
type Add struct {
// ãã£ãŒã«ãã¯æããªã
}
// Addåã«Calculatorã€ã³ã¿ãŒãã§ãŒã¹ã®Calculatoré¢æ°ãå®è£
func (x Add) Calculate(a int, b int) int {
return a + b
}
type Sub struct { }
func (x Sub) Calculate(a int, b int) int {
return a - b
}
func main() {
var add Add
var sub Sub
var cal Calculator // interface
cal = add // interfaceãæºããé¢æ°ãæã£ãŠããã®ã§ãèªåçã«ã€ã³ã¿ãŒãã§ãŒã¹ãå®è£
ããŠããããšã«ãªãã代å
¥ã§ãã
fmt.Println("å:", cal.Calculate(1, 2))
cal = sub
fmt.Println("å·®:", cal.Calculate(1, 2))
}
空ã€ã³ã¿ãŒãã§ãŒã¹ãé¢æ°ãæããªã空ã®ã€ã³ã¿ãŒãã§ãŒã¹ãå®çŸ©é¢æ°ããã¹ãŠå®è£ ããŠããåã¯ã€ã³ã¿ãŒãã§ãŒã¹ãå®è£ ããããšã«ãªãã®ã§ããã¹ãŠã®åã¯ç©ºã€ã³ã¿ãŒãã§ãŒã¹ãå®è£ ããŠããããšã«ãªãã
var empty interface {}
empty = "abc"
empty = 12345
empty = 3.14
_ = empty
é¢æ°ã1ã€ããæããªãã€ã³ã¿ãŒãã§ãŒã¹ã®å Žåããã®ã€ã³ã¿ãŒãã§ãŒã¹åã¯ãé¢æ°å+erããšããã®ãæ £ããã
type Reader interface {
Read(p []byte) (n int, err error)
}
åã¢ãµãŒã·ã§ã³ã¯ã€ã³ã¿ãŒãã§ãŒã¹åã®å€ãä»ã®åãžå€æãããšãããŸãã¯å€æã§ããã確èªãããšãã«äœ¿ãã
func main() {
// 空ã€ã³ã¿ãŒãã§ãŒã¹ã«stringåã®å€ãæ ŒçŽ
var i interface{} = "test"
// åã¢ãµãŒã·ã§ã³ã䜿ãstringåãž
var s string = i.(string) // åã¢ãµãŒã·ã§ã³
fmt.Printf("i: %T\n", i)
fmt.Printf("s: %T\n", s)
}
åã¢ãµãŒã·ã§ã³å€±ææã«ã©ã³ã¿ã€ã ãããã¯ãçºçãããªãããã§ãã¯ã«äœ¿ãã
func main() {
// 空ã€ã³ã¿ãŒãã§ãŒã¹ã«stringåã®å€ãæ ŒçŽ
var i interface{} = "test"
// åã¢ãµãŒã·ã§ã³ã«æåããäŸ
s1, ok := i.(string)
fmt.Println(s1, ok)
// åã¢ãµãŒã·ã§ã³ã«å€±æããäŸ
// stringåã¯dummyã¡ãœãããæããªãã®ã§å€æã§ããªã
s2, ok := i.(interface {
dummy()
})
fmt.Println(s2, ok)
}
åswitchæãéåžžã®switchæãšã¯ç°ãªããåŒswitchãå€ã«ãã£ãŠåå²ããã®ã«å¯Ÿããåswitchæã¯å€ãæã€åã«ãã£ãŠåå²ããã
func main() {
showType(nil)
showType(12345)
showType("abcdef")
showType(3.14)
}
func showType(x interface{}) {
switch x.(type) {
case nil:
fmt.Println("nil")
case int, int32, int64:
fmt.Println("æŽæ°")
case string:
fmt.Println("æåå")
default:
fmt.Println("äžæ")
}
}
é åã¢ã¯ã»ã¹ã
func main() {
var date [7]string
date[0] = "æ¥ææ¥"
date[1] = "æææ¥"
date[2] = "ç«ææ¥"
date[3] = "æ°Žææ¥"
date[4] = "æšææ¥"
date[5] = "éææ¥"
date[6] = "åææ¥"
// indexããŒãžã§ã³
for i := 0; i < len(date); i++ {
fmt.Print(date[i], " ")
}
// rangeããŒãžã§ã³
// æ¹è¡
fmt.Println()
for _, value := range date {
fmt.Print(value, " ")
}
fmt.Println()
}
- ã¹ã©ã€ã¹ â å¯å€é·
- é å â éå¯å€é·
ã¹ã©ã€ã¹åŒã
func main() {
// é
åã宣èš
x := [5]string{"a", "b", "c", "d", "e"}
// ã¹ã©ã€ã¹åã®å€æ°ã宣èš
var s1 []string
// é
åå
šäœãã¹ã©ã€ã¹
s1 = x[:]
fmt.Println(s1)
// ã€ã³ããã¯ã¹1~3ãŸã§ãã¹ã©ã€ã¹
s2 := x[1:4]
fmt.Println(s2)
// ã€ã³ããã¯ã¹3~ãã¹ã©ã€ã¹
s3 := x[3:]
fmt.Println(s3)
// ã€ã³ããã¯ã¹1~3ãã¹ã©ã€ã¹
s4 := x[:4]
fmt.Println(s4)
}
ã¹ã©ã€ã¹ã¯ãåç §åãã®1ã€ãGoèšèªã«ã¯ã¹ã©ã€ã¹ããããããã£ãã«ãšãã3ã€ã®åç §åããããããŒã¿ã®å®äœãæãããããŒã¿ãžã®åç §æ å ±ããæããªãã
ã¹ã©ã€ã¹ãå¯å€é·ãã©ã¡ãŒã¿ã«çŽæ¥åãæž¡ãã
func main() {
s := []string{"a", "b", "c"}
// 以äž2ã€ã®çµæã¯åã
test(s...)
test("a", "b", "c")
}
func test(s ...string) {
fmt.Println(len(s), s)
}
ãšã©ãŒãã³ããªã³ã°ã
func main() {
file, err := os.Open("test.txt")
if err != nil {
fmt.Println(err.Error())
// os.Exit(1)
}
file.Close()
fmt.Println("finish")
}
ç¬èªã®ãšã©ãŒåŠçã
type MyError struct {
message string
}
func (err MyError) Error() string {
return err.message
}
func main() {
val, err := hex2int("1")
fmt.Println(val, err)
val, err = hex2int("00000f")
fmt.Println(val, err)
val, err = hex2int("abcd")
fmt.Println(val, err)
val, err = hex2int("z")
fmt.Println(val, err)
}
// 16é²æ°æååãintåã«å€æãã
func hex2int(hex string) (val int, err error) {
// 1æåã¥ã€åãåºã
for _, r := range hex {
val *= 16
switch {
case '0' <= r && r <= '9':
val += int(r - '0')
case 'a' <= r && r <= 'f':
val += int(r-'a') + 10
default:
return 0, MyError{"äžæ£ãªæååã§ãã" + string(r)}
}
}
// æ»ãå€errã«ã¯åæå€ã§ããnilãè¿ã
return
}
åŠççµäºã
func main() {
f1()
}
func f1() {
panic("ãããã¯çºç ")
}
ãã£ãã«ã¯Goããã°ã©ã ã®äžã®éä¿¡æ©æ§ã§ããŽã«ãŒãã³éã«ãããéä¿¡ãåæãå€ã®åæã«äœ¿çšããã
func main() {
c := make(chan int, 10)
c <- 0
fmt.Println("cap:", cap(c))
fmt.Println("len:", len(c))
}
selectã¯è€æ°ã®ãã£ãã«ã«å¯ŸããŠåæã«éåä¿¡åŸ ã¡ãè¡ããšãã«äœ¿çšããã
goãšdockerã ç°å¢å€æ°ãã«ã©ãŒãã€ã³ãžã±ãŒã¿ãclonerã®goããŒãžã§ã³ãäœæããã
goclocãèªãã§ãããšãgcloneã®ã²ã©ãæžãæ¹ãç®ã«ã€ããåãæ§é äœã®äœ¿ãæ¹ããã¡ã€ã«ãã¢ãžã¥ãŒã«åå²ãäžéãå®äºãéåžžã«å匷ã«ãªã£ãã
Goã®IOã®è§£èª¬ãos.Fileåã®Readã¡ãœããã¯ä»¥äžã®ãããªå®è£ ãšãªã£ãŠããŸãã
- os.fileåã®Readã¡ãœãããåŒã¶
- 1ã®äžã§os.fileåã®readã¡ãœãããåŒã¶
- 2ã®äžã§poll.FDåã®Readã¡ãœãããåŒã¶
- 3ã®äžã§syscall.Readã¡ãœãããåŒã¶
- OSã«ãŒãã«ã®ã·ã¹ãã ã³ãŒã«ã§èªã¿èŸŒã¿åŠç
- networkãI/Oãšæãããããã³ãã¯ã·ã§ã³ããããŒã¿ãèªã¿åãã»æžã蟌ããšããããã
- Linuxã®èšèšææ³ãšããŠâeverything-is-a-file philosophyâãšãããã®ããããããŒããŒãããã®å ¥åããããªã³ã¿ãŒãžã®åºåããããŒããã£ã¹ã¯ããããã¯ãŒã¯ããã®I/Oããããšãããããã®ããã¹ãŠãOSã®ãã¡ã€ã«ã·ã¹ãã ã«ãããã¡ã€ã«ãžã®I/OãšããŠæããããšããææ³ããããã¯ãŒã¯ããã®ããŒã¿èªã¿åãã»æžã蟌ã¿ããOSå éšçã«ã¯éåžžã®ãã¡ã€ã«I/Oãšå€ãããªãããã®ããããããã¯ãŒã¯ã³ãã¯ã·ã§ã³ã«å¯ŸããŠããéåžžãã¡ã€ã«ãšåæ§ã«fdãäžãããã
- ãã¡ã€ã«èªã¿èŸŒã¿ã§ããããã¯ãŒã¯ã³ãã¯ã·ã§ã³ã§ããã·ã¹ãã ã³ãŒã«socket()ãåŒãã§ãfdãååŸããfdãå éšãã£ãŒã«ãã«å«ãã åãçæãããšããã¯å ±é
- ãªã¹ããŒããã³ãã¯ã·ã§ã³ãåŸã = ãªã¹ããŒããfdãåãåºããŠããããTCPConnã«ã©ãããã
ããŠã³ããŒãããŠãããšãå ã«ãªããžããªåã衚瀺ããŠãããšããçµæã«å¿ããŠèšå·ãã€ããã
github@gclone... â (10s)
github@go............ â (0.6s)
...
40.4s
10.1G
ã€ã³ã©ã€ã³ã«è¡šç€ºããã®ãããããããspinnerãšã³ã³ããªã¯ãããŠãã®ãã
ã¢ã€ãã¢ã
- èšèªå¥ã®ãªããžããªæ°ãè¡æ°ãã³ãããæ°
- ã·ãŒã«ã
- å®æçã«GitHub Actionsã§ãã«ãããããšã§ãæ°å€ãç»åã«åæ ããã
- ããŒã¿ã¹ãã¢çšãªããžããªãšããèãæ¹ãæ·±ãã(octcovãupptimeçãª)
- æ±çšçãªããŒã¿ã¹ãã¢ãšããŠçšãã
- å¥ãªããžããªããç°¡åã«æ±ããworkflowãäœæãã
- ããŒã¿ã¹ãã¢ãªããžããªã®URLãšãããŒã«ãã£ãŠãä¿åãã
- ããŒã¿ãå ã«ç»åãªãçæããŠãæç³»åãèŠãããããã«ãã
- ãªããžããªäžèŠ§ãäœããã³ãããæ°ãèšèªæ å ±ãäžèŠ§ãã
- ããŒã¿ã¹ãã¢ã«ä¿åãå å·¥ãããã圢ã«ãã
- ç»å/jsonã§åºåãã
- ä»ãµã€ãã«è²Œããããã«ãã
ç·ã³ããã: 5000 | åå | æŠèŠ | èšèª | |----------+----------------+------------| | .emacs.d | emacs dotfiles | Emacs Lisp | | dotfiles | system config | Shell | | gclone | git clone tool | Go | | èšèª | ãªããžããªæ° | ã³ãããæ° | |------------+--------------+------------| | Go | 4 | 100 | | Ruby | 5 | 200 | | Emacs Lisp | 2 | 100 |
- æ±çšçãªããŒã¿ã¹ãã¢ãªããžããª(é ä¿¡çš)ãããŒã«ãå®è¡ããŠæŽæ°ãã
- CLIããŒã«
- æ å ±ååŸ
- jsonåºå
- ç»ååºå
- README.mdåºå
- ã³ãããæ©èœ
- ããã³ããšã³ã
ã³ãããæ°ãåãã®ãé£ãããGraphQLã§åãããã«ããã
èšèªå¥ã®è²ã®äžžç»åãçæããããã±ãŒãžã- keyã ããå¥ã®ã¹ã©ã€ã¹ã«ããŠããœãŒãããã
- keyãã€ãã¬ãŒãããŠãmapã®äžèº«ãåãåºã
- golang/go: The Go programming language
- TestStdErrorHander
- hexdecimal
- 31, 42, 45, 52, 75, 86, 105, 115, 162, 184, 238, 252, 297
ã€ã³ã¿ããªã¿ãå®è£ ããã
- åå¥è§£æãã§ãŒãºãæååãããŒã¯ã³åã«å€æ
- æ§æ解æãã§ãŒãºãããŒã¯ã³åãASTã«å€æ
- ãã¯ãå±éãã§ãŒãºãASTãåãåããä¿®æ£ããŠãè¿åŽ
- è©äŸ¡
äžéããã£ãããããŸãè ã«èœã¡ãŠãªããéšåçãªã³ãŒãã®å€ãã¯èªãã§ç解ã§ããããèªåã§å¥ã®ããšã«å©çšããããæ¡åŒµã¯å šãã§ãããã«ãªãã
åç»æ€çŽ¢ã¢ããªãé¡æã«ãNuxtãšGoã䜿ã£ãã¢ããªéçºãããæ¬ã
ãšããã©ããSDKã®ããŒãžã§ã³ã®éãã§æ¬ã®èšè¿°ã§ã¯åããªããšããããããã©ããééã£ãããããjsonããŒã¯ã³ãåãåãç®æãããŸãã§ããªããFirebaseãžã®ãã°ã€ã³ç¶æ ãå€æããç®æãããŸããã£ãŠãªãã®ã§ãããŒã¿ããŒã¹ã®åãã確ãããããŠããªãã
ããã¯ãšã³ãGo, ããã³ãReactã§äœãã æŽåœ¢ã®æ¹æ³ãèªããäž»èŠãªé¢æ°ãèŠãŠããã
https://github.com/golang/go/blob/51af90445696772703ed88d967e8c23c8e9e992d/src/cmd/gofmt/gofmt.go#L229
- ãã¡ã€ã«èªã¿èŸŒã¿
- aståãåºã
- ãã©ãŒããã
- å·®åãããã°ãçµæã«å¯Ÿããåçš®åŠç
- è€æ°ãã¡ã€ã«ãªãã·ã§ã³ãããã°ããã¡ã€ã«åãããªã³ã
- æžã蟌ã¿ãªãã·ã§ã³ãããã°ããã¡ã€ã«ã«æžã蟌ã¿ãæåã«ããã¯ã¢ãããå¥ãã¡ã€ã«ã«ä¿åããç®æšãã¡ã€ã«ãžã®äžæžãã«ãšã©ãŒãããã°æ»ããããã«ããããšã©ãŒããªãã£ãå Žåã¯å®äº
- å·®å衚瀺ãªãã·ã§ã³ãããã°ãå·®åãããªã³ã
https://github.com/golang/go/blob/51af90445696772703ed88d967e8c23c8e9e992d/src/cmd/gofmt/gofmt.go#L387
çåã
fdSem
ãšã¯- fdSem guards the number of concurrently-open file descriptors.
- file descriptor semaphore ããã»ããã©ãšã¯ãåæå®è¡ãå¶åŸ¡ããä»çµã¿
- å®çŸ©ã® make(chan bool, 200) ã¯ãããã¡äœæããã£ãã«ã«äžæããŒã¿ãä¿åãã
fdsem <- true
ã¯å ¥ãã<-fdSem
ã¯åãåºã- ãã¡ã€ã«é¢ä¿ã®åŠçãå ¥ããšãã«fdSemãã³ã³ãããŒã«ããŠãfile descriptorã®äžéãè¶ ããªãããã«ããŠãã
weight
ãšã¯- maxWeightã¯ã³ã¢æ°ã®ç°å¢å€æ°ããèšç®ããå€ã䜿ã
- maxWeightã¯æ倧ã®åææ¥ç¶æ°ã®ããšã§ãweightã¯ãã®æ¥ç¶æ°ã®ã«ãŠã³ãã®ããšãæ¥ç¶ãå¢ãããšã«ãŠã³ããæžãã0ã«ãªããšã»ãã®ãŽã«ãŒãã³ã¯äžŠåå®è¡ã§ããªã
- weightã¯ãã¡ã€ã«ãµã€ãºããèšç®ãã
- ãã¡ã€ã«ãµã€ãºã«ãã£ãŠåæå®è¡æ°ãå¶åŸ¡ããâŠãšããããšããããŸããã³ãšããªã
sequencer
ãšã¯- ã¹ã©ã€ã¹çã§ã¯ãªãããprevãã£ãŒã«ãã§èŸ¿ããã°ã«ãŒããã³ã°æ§é ã«èŠãã
- weight, ãã¡ã€ã«åŠçãå«ãç¡åé¢æ°ãå ¥ã£ãŠãã
- ãšã©ãŒãåºãç¡åé¢æ°ãå ¥ããããšããã
çµå±å šç¶ãã³ãšæ¥ãŠãªãã
ãŸããããã¡ã®æŠå¿µãç解ããããšãå¿ èŠããã解説ããŠãã£ããããããã®ãèªåã§ã³ãŒããã調æ»ã§ããããã«ãªãããã
ãããã€ãæ°ã«éãããŸã§bufioã®å éšãããã¡ã«ãããŠããåŠçãããããããæ®éã®bufioãšioã®éãã
https://github.com/golang/go/blob/122a22e0e9eba7fe712030d429fc4bcf6f447f5e/src/bufio/bufio.go#L662-L685
ãšãã¹ããŒããã¡ã®Goèšèª äžæµã®ã³ãŒãããå¿çšåãåŠã¶ | Gihyo Digital Publishing ⊠æè¡è©è«ç€Ÿã®é»åæžç±
[[https://selfnote.work/20210516/programming/golang-design-pattern-prototype/][[Goèšèª]Prototypeãã¿ãŒã³ãåŠãŒã | ã»ã«ãããŒã]]
ãã¹ãé§åéçºã§GOèšèªãåŠã³ãŸããã - ãã¹ãé§åéçºã§GOèšèªãåŠã³ãŸããã
- æšæºã©ã€ãã©ãªã䜿ã£ãŠã¿ããšãã«ãã¹ãã§åäœãã§ãã¯ããŠã¿ããšãå匷ã«ãªã
Goæšæºã©ã€ãã©ãªã¯æ¬åœã«è¯ãã§ããæéããããŠå匷ããŠãã ããã ãã®ããã«io.Writerã€ã³ã¿ãŒãã§ãŒã¹ã«ããçšåºŠæ £ããŠããããšã§ããã¹ãã§bytes.Bufferã WriterãšããŠäœ¿ãããšãã§ããæšæºã©ã€ãã©ãªã®ä»ã®Writerã䜿ã£ãŠã³ãã³ãã©ã€ã³ã¢ããªããŠã§ããµãŒãã§é¢æ°ã䜿ãããšãã§ããŸãã æšæºã©ã€ãã©ãªã«æ £ããã»ã©ããããã®æ±çšã€ã³ã¿ãŒãã§ã€ã¹ã衚瀺ãããç¬èªã®ã³ãŒãã§åå©çšããŠããœãããŠã§ã¢ãããŸããŸãªã³ã³ããã¹ãã§åå©çšå¯èœã«ããããšãã§ããŸãã
ã·ã¹ãã ã®å®è¡ã«ãšã£ãŠå®è£ ãæ¬åœã«éèŠã§ãªãéãããã¹ããæçšãªåäœããã§ãã¯ããããã«ããŠãã ããã
- ãªãã¡ã¯ã¿ãªã³ã°ã®å®çŸ©ã§ã¯ãã³ãŒãã¯å€æŽãããŸãããåäœã¯åãã§ããçè«çã«ãªãã¡ã¯ã¿ãªã³ã°ãè¡ãããšã«æ±ºããå Žåã¯ããã¹ããå€æŽããã«ã³ããããå®è¡ã§ããã¯ãã§ããã ãããã¹ããæžããšãã¯èªåããŠãã ãã
- å¿ èŠãªåäœãå®è£ ã®è©³çŽ°ããã¹ãããŠããŸããïŒ
- ãã®ã³ãŒãããªãã¡ã¯ã¿ãªã³ã°ããå Žåããã¹ãã«å€ãã®å€æŽãå ããå¿ èŠããããŸããïŒ
- ãã¹ãã3ã€ä»¥äžã®ã¢ãã¯ã§åäœããŠããå Žåãããã¯å±éºä¿¡å·ã§ããããã«æããŸãïŒãã¶ã€ã³ãåæ€èšããæéïŒ
TDDã¢ãããŒãã®è©³çŽ°
- ããããªäŸã«çŽé¢ããå Žåã¯ãåé¡ããèãã¹ã©ã€ã¹ãã«å解ããŠãã ããããŠãµã®ã®ç©Žã«å ¥ã蟌ã¿ããããã°ãã³ãã¢ãããŒãããšããªãããã«ãã§ããã ãæ©ã_testsã§åäœãããœãããŠã§ã¢ã䜿çšã§ããããã«ããŠãã ããã
- åäœãããœãããŠã§ã¢ãå ¥æããããå¿ èŠãªãœãããŠã§ã¢ã«ãã©ãçããŸã§å°ããªã¹ãããã§ç¹°ãè¿ãã®ãç°¡åã§ãã
éœåºŠprintããã®ã§ã¯ãªãã貯ããŠãããŠã衚瀺ããç®æã§æŽåœ¢ããŠè¡šç€ºãããã衚瀺éšåãšåŠçãåé¢ãããå¹æããããäœãå ¬éãããŠããããŒã«ãåèã«ããã°ã§ãããã
- åçŽã«1éå±€ã®çµæã§ããã°ãæ§é äœã«å ¥ããŠæ®éã«è¿ãã°ãã
- è€æ°éå±€ã§ããã°ã工倫ãå¿ èŠãã
[python 2/4]RUN pip3 install [build 2/13] COPY . .ã¹ã³ãŒãã®è§£èª¬ã
ã¹ã³ãŒãã«ã¯4ã€ã®çš®é¡ãããã
- ãŠãããŒã¹
- ãã¡ã€ã«
- ããã±ãŒãž
- ããŒã«ã«
ããããã®çš®é¡ã®ã¹ã³ãŒãã§ã¯ä»¥äžã®ãªããžã§ã¯ããå®çŸ©ã§ããã
ãŠãããŒã¹ | ãã¡ã€ã« | ããã±ãŒãž | ããŒã«ã« | |
---|---|---|---|---|
çµã¿èŸŒã¿é¢æ°(types.Builtin) | â | |||
nil(types.nil) | â | |||
å®æ°(types.Const) | â | â | â | |
åå(types.TypeName) | â | â | â | |
é¢æ°(types.Func) | â | |||
å€æ°(types.Var) | â | â | ||
ããã±ãŒãžå(types.PkgName) | â | |||
ã©ãã«(Label) | â |
æ¯èŒå¯èœãªåã®èª¬æã
- æ¯èŒå¯èœ
- çåœå€
- æŽæ°å€
- æµ®åå°æ°ç¹å€
- è€çŽ æ°å€
- æåå
- ãã€ã³ã¿
- ãã£ãã«
- ã€ã³ã¿ãã§ãŒã¹
- åçåãšåçå€ã®2ã€ããæ§æããã
- åçåã
%T
verbã§è¡šç€ºã§ãã
- æ§é äœ(æ¡ä»¶ãã)
- é
å(æ¡ä»¶ãã)
- æ§æãããã£ãŒã«ããèŠçŽ ã«æ¯èŒã§ããªãåãããå Žåã¯æ¯èŒã§ããªã
- æ¯èŒå¯èœã®å Žåã
==
æŒç®åã!=
æŒç®åã§æ¯èŒã§ããã - é åºä»ãå¯èœãªå Žåã¯ããã«
<
,<=
,>
,>=
ã䜿çšã§ãã
var x, y any = 100, 200
fmt.Println(x == y)
var x, y any = int(100), int32(100)
fmt.Println(x == y)
ãŸãšãã
- åçåãéãå Žåã¯å¿ ãfalse
- åçåãåãã§ã©ã¡ããã®åçåãæ¯èŒäžå¯èœãªå Žåã¯ãããã¯
- åçåãåãã§comparableã§ãã€åçå€ãåãå Žåã¯true
- åçåãåãã§comparableã§ãã€åçå€ãéãå Žåã¯false
æ€ç¥ããŠãªãçæãåé¡ãªãã£ãã
- type: objectãã€ããŠãªãé ç®ããã£ã
- ãã®é ç®ã¯arrayã ããåã«æã£ãŠããããã®ãããèªèº«ã®typeãarrayã«ãªã£ãŠãã
- ãããããåã®é ç®ã§èªèº«ã®typeã決å®ãããã»ãšãã©ã¯è€ååã§ãobjectã«èªåã§æ±ºå®ããŠåé¡ãªãããä»åã®ããã«åé¡ãããã±ãŒã¹ããã
Goãªããããã·ã¹ãã ããã°ã©ãã³ã° | æžå· ããã, ãã£ã¡ã |æ¬ | é販 - Amazon.co.jp
éäžãŸã§èªãã ããããŸãããããããªãã®ã§åŸåãã«ããã
ã·ã¹ãã ããã°ã©ãã³ã°ãGoã§åŠã¶æ¬ã
- ãŸããããã¬ç°å¢ãæŽããããšãã
- ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ã«å¯Ÿå¿ãããã®ã¯ãéåžžã®ãã¡ã€ã«ã«éããªããæšæºå ¥åºå/ãœã±ãã/OS/CPUã«å èµãããŠããä¹±æ°çæã®ä»çµã¿ãªã©ããã¡ã€ã«ã§ã¯ãªããã®ã«ããã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãå²ãåœãŠãããã©ãããã¡ã€ã«ãšåãããã«ã¢ã¯ã»ã¹ã§ãã
- OSã¯ãããã»ã¹ãèµ·åããããšãŸã3ã€ã®ç䌌ãã¡ã€ã«ãäœæããããããã«ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãå²ãåœãŠãã0ãæšæºå ¥åã1ãæšæºåºåã2ãæšæºãšã©ãŒåºå
- å¯èœãªéããã¹ãŠã®ãã®ããã¡ã€ã«ãšããŠæœè±¡åãããŠãã
- goèšèªã§ã¯ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ã®ãããªå ±éåã®ä»çµã¿ãèšèªã¬ãã«ã§æã£ãŠOSã«ããå·®ç°ãåžåããŠãããio.Writer
- ã€ã³ã¿ãŒãã§ãŒã¹ã¯ãæ§é äœãšéã£ãŠäœãããå®äœãæã€ãã®ãè¡šãã®ã§ã¯ãªãããã©ããªããšãã§ããããã宣èšããŠããã ã
- ãªã¯ãšã¹ãã§ã¯ã¹ããŒã¹ã¿ãŒãã«ãã£ãŠãæé©ãªé床ã決å®ããŠããã倧ããªãã¡ã€ã«è»¢éãããšãã«åŸã ã«é床ãäžãã£ãŠããã®ã¯ãã®ããã
- Linuxã®ãã¡ã€ã«ã®ç®¡çæ å ±ãæ ŒçŽããŠããé åããinodeãšãã
- Linuxã§ãã¡ã€ã«ãèªã¿æžãããå Žåã«ã¯ããŸããããã¡ã«ããŒã¿ãæ ŒçŽãããããã§ã«ãããã¡ã«èŒã£ãŠããŠããã®ãã¡ã€ã«ã«å¯Ÿããæžã蟌ã¿ãè¡ãããŠããªããªããããã¡ã ãã«ããã¢ã¯ã»ã¹ããªã
- .envãã¡ã€ã«ãå©çšããã¢ã€ãã¢ã¯ãRailsã§ã®çºæããã
- OSãå®è¡ãã¡ã€ã«ãèªã¿èŸŒãã§å®è¡ããã«ã¯ããã®ããã®ãªãœãŒã¹ãçšæããªããã°ãªããªãããã®ãããªãªãœãŒã¹ããŸãšããããã°ã©ã ã®å®è¡åäœãããã»ã¹
- ã«ãŒãã«ã¯æ°ããããã»ã¹ãäœããã³ã«åããã»ã¹ã§ã©ããã£ãå ¥åºåãè¡ããããã®ç®¡çããŒãã«ãã€ããããã®ã€ã³ããã¯ã¹å€ããã¡ã€ã«ãã£ã¹ã¯ãªãã¿
- ããã»ã¹ãæããã°ã«ãŒããšãããã®ããããããã»ã¹ã°ã«ãŒã(å¥åãžã§ã)ããã€ãã䜿ããšåãããã»ã¹ã°ã«ãŒãã«ãªã
- ã·ã°ãã«ã¯ããã»ã¹ã«å¯ŸããŠéããã
- ã·ã¹ãã ã³ãŒã«
- ããã»ã¹ â OSã«ãŒãã«
- ã·ã°ãã«
- OSã«ãŒãã« â ããã»ã¹
- ã¹ã¬ãããCPUã³ã¢ã«å¯ŸããŠãããã³ã°ãããã®ã«å¯Ÿããgoroutineã¯OSã®ã¹ã¬ããã«ãããã³ã°ããã
- goroutineã¯OSã®ã¹ã¬ãããšæ¯èŒããŠã¿ã¹ã¯åãæ¿ãã®ã³ã¹ããäœã
- ã¹ã€ããã«ã¯åã®åŠçã䜿ã£ãŠããã¬ãžã¹ã¿ã®éé¿ãå¿ èŠã«ãªãããéé¿ãæå°éãæžãã³ãŒãäœçœ®ã«ã¹ã€ããã®ããã®ã³ãŒããåã蟌ãã
- åæã¹ã¿ãã¯ã¡ã¢ãªã®ãµã€ãºãå°ãããã¡ã¢ãªç¢ºä¿ã¯åŠçæéããããã®ã§ãèµ·åæéã§ã¯å°ããã»ããæå©
- ãªã©ã«ãã£ãŠãgoroutineã¯èµ·åæéãåãæ¿ãæéãOSã®ã¹ã¬ãããã1000åã®ãªãŒããŒã§é«é
- GoãæäŸãã䞊è¡ã»äžŠååŠçã®3èŠçŽ
- goroutine: å®è¡
- ãã£ãã«ã»ã³ãã¥ãã±ãŒã·ã§ã³
- select: 調å
- 䞊è¡ã»äžŠååŠçã®å®çŸææ³
- ãã«ãããã»ã¹
- ã€ãã³ãé§å
- ãã«ãã¹ã¬ãã
- ã¹ããªãŒãã³ã°ã»ããã»ãã·ã³ã°
- ã¹ã©ã€ã¹ã®è£ã«ã¯é åããããå®éã«ã¯é åãåç §ãããŠã£ã³ããŠ(察象ã®é åã®ã¹ã¿ãŒãäœçœ®ïŒçµäºäœçœ®ã確ä¿æžã¿ã®ãµã€ãºã®3ã€ã®æ å ±ãæã€)ã§æ§æãããŠãã
- ããã¯ãšã³ãã®é åã«å¯Ÿãã䜿ããããããã³ããšã³ããšããŠæäŸãããŠããã®ãã¹ã©ã€ã¹
- ã¹ã©ã€ã¹ã®å®æ
ã¯3ã€ã®æ°å€ãšãã€ã³ã¿ãæã£ã24ãã€ãã®ããŒã¿
- ã¹ã©ã€ã¹ã®å é ã®èŠçŽ ãžã®ãã€ã³ã¿
- ã¹ã©ã€ã¹ã®é·ã
- ã¹ã©ã€ã¹ã確ä¿ããŠããèŠçŽ æ°
- ãªãã©ã«ã£ãŠãªãã
- ãªãã©ã« - Wikipedia
- ãœãŒã¹ã³ãŒãå
ã«å€ãçŽæ¥è¡šèšãããã®
int x = 7;
ã ãš7double pi = 3.14;
ã ãš3.14string s = "hello";
ã ãšâhelloâ
- ããŒã¯ã³ãšã¯éãã®ããªãããŒã¯ã³ã¯å€ã ãã§ãªãèå¥åãäºçŽèªãå«ã
- ãªãã©ã«ïŒçŽå€ïŒãšã¯ - æå³ããããããã - ITçšèªèŸå ž e-Words
- ãªãã©ã«ãšã¯ãã³ã³ãã¥ãŒã¿ããã°ã©ã ã®ãœãŒã¹ã³ãŒããªã©ã®äžã«ãç¹å®ã®ããŒã¿åã®å€ãçŽã«èšèŒãããã®ããŸãããã®ããã«å€ãã³ãŒãã«æžãå ¥ããããã«å®ããããŠããæžåŒã
- ã»ã¬ã¯ã¿ã£ãŠãªãã
x.f
ã¯å€x
ã®ãã£ãŒã«ãf
ããŸãã¯ã¡ãœããf
ã瀺ã
- å®çŸ©å(defined type)ã£ãŠãªãã
- äºåå®çŸ©ãããåããç¬èªã«å®çŸ©ãããå
type S []int
ã®S
type T int
ã®T
ãšint
- defined typeã§ãªãåã¯è€åå
- åãªãã©ã«ã£ãŠãªãã
- Goã®ååäžæ§ãç解ãã
- ä»ã®åãå©çšããŠæ§æãããå
var a [5]int
ã«ããã[5]inttype B int
(Bã¯åå)var b []B
ã«ããã[]B- ãªãã©ã«äžã«ä»ã®åã䜿ãããªããfunc()ããstruct{}ãšãã£ãåãªãã©ã«ãååšãã
- åãªãã©ã«ã䜿ã£ãŠç€ºãããåã¯ãåå®çŸ©ãè¡ãããŠããªãããdefined typeã§ã¯ãªã
- åãªãã©ã«ã®çš®é¡
- èŠçŽ åãæã€
- é åå
- ã¹ã©ã€ã¹å
- ãããå
- ãã£ã³ãã«å
- ããŒåãæã€
- ãããå
- ãã£ãŒã«ãåãæã€
- æ§é äœå
- ããŒã¹ã®åãæã€
- ãã€ã³ã¿å
- ä»®åŒæ°åãçµæåãæã€
- é¢æ°å
- èŠçŽ åãæã€
- åãªãã©ã«ã«ãã£ãŠç€ºãããåå士ãåäžãã©ãããå€å®ããã«ã¯ãåãªãã©ã«ã®æ§é ãåäžãã€ãåãªãã©ã«äžã«çŸããåãåäžã§ããããšã確èªããå¿ èŠããã
- åãªãã©ã«ããšã«ãåäžæ§ã®æ¡ä»¶ããã
- ã€ã³ã¿ãŒãã§ãŒã¹åã¯ä»»æã®åã䜿ã£ãŠæ§æãããããã§ã¯ãªããã€ã³ã¿ãŒãã§ãŒã¹åã¯ã¡ãœãããæã¡ãããããã®ã¡ãœããã¯é¢æ°åãæã€
- underlying type(åºåºå)ã£ãŠãªãã
- ãã¹ãŠã®åã¯underlying typeãæã€
- äºåã«å®çŸ©ãããåããåãªãã©ã«ã«ãã£ãŠç€ºãããåã®underlying typeã¯ãã®åèªèº«
int
-> åºåºå: intstring
-> åºåºå: string[]int
-> åºåºå: []intstruct{}
-> åºåºå: struct{}
- ãã以å€ã®åã®underlying typeã¯å宣èšã®å¯Ÿè±¡ã«ãã£ãŠæ±ºãŸã
- 2ã€ã®å宣èš
type A string
-> å宣èštype A string
-> Aã®åºåºå: stringtype B A
-> Bã®åºåºå: stringtype C []int
-> Cã®åºåºå: []int
type B = int
-> ãšã€ãªã¢ã¹å®£èštype A string
-> defined typetype B = A
-> Bã®åºåºå: stringtype C = []int
-> Cã®åºåºå: []int
- 2ã€ã®åã®ããããdefined typeã§ãªãå Žåãããããã®åã®underlying typeã®åãªãã©ã«ãæ§é çã«çããå Žåã«åäžãšãªã
- defined typeã§ãªãåãšã¯ãåãªãã©ã«ãšåãšã€ãªã¢ã¹
- åãªãã©ã«ã®underlying typeã¯ãã®åãªãã©ã«èªèº«
- ååäžæ§ã«ãããŠunderlying typeã®èæ ®ãå¿ èŠãªã®ã¯åãšã€ãªã¢ã¹ã®ã¿
type NamedMap = map[string][]int
- NamedMapã®åºåºåã¯map[string][]int
- m1ãšm2ã¯underlying typeã®åãªãã©ã«ã®æ§é ãåäžãªã®ã§åäž
var m1 map[string][]int
var m2 NamedMap
- åèã«ãªãçšèª [[https://zenn.dev/senk/articles/91fa080844bb12][[Go] èšèªä»æ§æžã«åºãŠããåé¢é£ã®çšèªãŸãšã]]
- Goèšèªã®defined typeãšã¯äœã
- 修食èå¥å
- ããã±ãŒãžåãã€ããŠä¿®é£Ÿãããèå¥å
- PackageName â.â identifier .
- 修食èå¥åã¯ãã€ã³ããŒããããªããã°ãªããªã
- runeã®äŸã§çœéµ¬ãåºãŠããŠç¬ã
- çµç«¯æ
- return, goto, panicâŠ
- åŒæ(expression statements)
- é¢æ°åŒã³åºããšã¡ãœããåŒã³åºããšåä¿¡æŒç®ã¯ãæã³ã³ããã¹ãã«çŸããããã®ãããªæã¯ãäžžæ¬åŒ§ã§å²ãŸããŠããå¿ èŠããã
- ã¢ãã¬ã¹æŒç®å
- ãã€ã³ã¿ãŒéæ¥åç §
- 誀å
- èªèŠå®£èš
- é¢æ°å ã
- ããŒãå šãå«ãŸãªãã¯èŠçŽ ãªã¹ã
- ããèŠçŽ ãããŒããã€ãªãã°ïŒãã¹ãŠèŠçŽ ã
- é¢æ°ã¯ãªãã©ã«ã¯
- ããããèŠçŽ ã
- å®æ°ã€ã³ããã¯
- ã€ã³ããã¯ã¯
- 次ã®é¢ä¿ãæºè¶³ãã
- é£ç¶ããèŠçŽ ããã®æååã®ãã€ããã¡
- ã§ããã¹ã©ã€ã¹ãçæããã
- çµåæ§ãäžæžããŠ
- fStmt =
- ä»æ§ã§ãã
- æå²ã芪é¢æ°
- ãããã£ãŠ
- ãæºè¶³ãã
- ãåºæºãšããã®
ããããªWebã¢ããªã®çŽ¹ä»ã
- sync.Onceåã䜿ããšé¢æ°ã1åããå®è¡ããªãããšãä¿èšŒã§ãã
- Newã¡ãœãã, Offã¡ãœãã, Tracerã€ã³ã¿ãŒãã§ãŒã¹
åŒã³åºãããæç¹ã§ã¯ãŸã å©çšã§ããªãå€ã«äŸåããŠãããšããããšãããããŸãããããã§ãäœããã®å¯Ÿçãå¿ èŠã«ãªããŸããäŸãã°ãå¿ èŠãªãã£ãŒã«ããåå¥ã«åŒæ°ãšããŠæž¡ããšããå€æŽãèããããŸãããããããããããšã€ã³ã¿ãã§ãŒã¹ãäžå®å®ãªãã®ã«ãªã£ãŠããŸããŸããããããã®Avatarã®å®è£ ã§æ°ããçš®é¡ã®æ å ±ãå¿ èŠã«ãªããã³ã«ãã¡ãœããã®ã·ã°ããã£ãŒãå€æŽããªããã°ãªããªããªãããã§ãã代ããã«ãAvatarã®å®è£ ãå¿ èŠãšããæ å ±ãã«ãã»ã«åããæ°ããåãå®çŸ©ããããšã«ããŸãã
- ã¡ãã»ãŒãžãéä¿¡ããããã³ã«ã¢ãã¿ãŒç»åURLãçæãããšã¹ã±ãŒã«ããªããã¢ãã¿ãŒURLã¯ã¯ãããŒã®äžã«ãã£ãã·ã¥ããããšã«ãã
- ã€ã³ã¡ã¢ãªè¡šçŸ
- äœããã®æ§é ãæã€ããšãåæãšããæ±ãæ¹
- ãªã¹ã
- é å
- æ§é äœ
- äœããã®æ§é ãæã€ããšãåæãšããæ±ãæ¹
- ãã€ãåè¡šçŸ
- ãã ã®ãã€ãåãšããŠæ±ããããŒã¿ãã®ãã®ã«äœãæžããŠããããæ°ã«ããå¿ èŠããªã
- ãã¡ã€ã«ãžã®æžã蟌ã¿
- ãããã¯ãŒã¯ãžã®åä¿¡
ãšã³ã³ãŒãã¯ã€ã³ã¡ã¢ãªè¡šçŸãããã€ãåè¡šçŸãžã®å€æã®ããšã
- Goæ§é äœããjsonãçæãã
- å¹³æããæå·æãçæãã
ãã³ãŒãã£ã³ã°ã¯ãã€ãåè¡šçŸããã€ã³ã¡ã¢ãªè¡šçŸãžã®å€æã®ããšã
- jsonããGoæ§é äœãçæãã
- æå·æããå¹³æãçæãã
Unmarshalã¯ã察å¿ããŠãªãjsonã®ãã£ãŒã«ãããããšåãããŒãããããŠãŒãå€ãå ¥ããããã®æåãé²ããããšãã¯ãUnmarshalã§æžã蟌ãå ã®å€æ°ãinterface{}åã«ããŠå ¥ããããããåã¢ãµãŒã·ã§ã³ã§ç¢ºãããã°ããã
Goã®æšæºããã±ãŒãžã詳解ããæ¬ã Goã®è§£èª¬éãhttps://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/runtime/rt0_linux_amd64.s#L7-L8
https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/runtime/asm_amd64.s#L15-L18
https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/runtime/proc.go#L115
https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/runtime/runtime2.go#L414
https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/runtime/asm_amd64.s#L183-L187
- TLS
- Thread Local Storage
- runtimeãŸããã§ã¯
g
ã¯goroutineãm
ã¯ã¯ãŒã«ãŒã¹ã¬ããããã
https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/runtime/os_linux.go#L346-L368
https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/runtime/proc.go#L694-L779
https://github.com/golang/go/blob/a031f4ef83edc132d5f49382bfef491161de2476/src/runtime/proc.go#L131-L132
- ãããã¬ã§ã¹ãããã€ã³ããããšãããªãã¯ãªé¢æ°ãèŠã€ããŠããããåŒã³åºãããã«ãããšå床ãããã¬ãå®è¡ãããšãã«çŽ æ©ãç®çã®é¢æ°ãŸã§ãã©ãçãããããªããå€æ°ãŸããã調ã¹ãŠåãåŒæ°ã§æž¡ããããã«ãã
GoãåŠãã åæã«æžããããããã«ããã³ãŒãã«ãªã£ãŠããã®ãçŽãã
Goã®ãµãŒããŒã®è§£èª¬ãhttps://github.com/kd-collective/go/blob/2eca0b1e1663d826893b6b1fd8bd89da98e65d1e/src/net/http/server.go#L2503-L2515
ååéäžã§ããããªããªã£ãã®ã§ããŸãèªã¿å§ããã