Size: a a a

Go на двоих

2020 February 26
Go на двоих
Note #61 govalidate 🌳

TIL: Если запустить govalidate, то можно убедиться, что вы используете не последнюю версию  Go 😜

До:
$ govalidate
[✗] Go (go1.13)
   Your current Go version (go1.13) is old.
   Current Go versions are go1.14, go1.13.8, .
   Visit https://golang.org/dl/ for a new version.
[✔️] Checking if $PATH contains "/Users/andrii/workspace/bin"
[✔️] Checking gcc for CGO support
[✔️] Vim Go plugin

после upgrade go:
$ govalidate
[✔️] Go (go1.14)
[✔️] Checking if $PATH contains "/Users/andrii/workspace/bin"
[✔️] Checking gcc for CGO support
[✔️] Vim Go plugin

P.S. thanks Jaana Dogan @rakyll for govalidate
P.P.S $ go get -u github.com/rakyll/govalidate
источник
2020 March 01
Go на двоих
Note #62 GopherCon Russia 2020

Мои старые друзья 28 марта проводят GopherCon Russia 2020! В этому году у меня не получается поехать :(

Но! У меня есть 1 билет, который я подарю тому, кто первый напишет в чате канала(кнопка discuss), как придумали название известной консольной утилиты “grep”?

Удачи :)

P.S. подробности и регистрация на сайте: https://www.gophercon-russia.ru/
источник
2020 March 02
Go на двоих
Note #63 A new Go API for Protocol Buffers

В официальном #golang блоге появилась статья про новый Go API для Protocol Buffers.

Рекомендую почитать! ->

https://blog.golang.org/a-new-go-api-for-protocol-buffers
источник
2020 April 12
Go на двоих
Note #64 New net/url.URL.Redacted method in go 1.15

В Go1.15 появится удобный метод net/url.URL.Redacted [1], по сути, похож на url.URL.String(), только заменяет пароли на xxxxxxx, будет удобно для логирования:

package main

import (
 "fmt"
 "net/url"
)

func main() {
 u := &url.URL{
   Scheme: "https",
   User:   url.UserPassword("user", "password"),
   Host:   "example.com",
   Path:   "foo/bar",
 }
 fmt.Println(u.Redacted())
 u.User = url.UserPassword("me", "newerPassword")
 fmt.Println(u.Redacted())
}
// gotip run main.go
// https://user:xxxxx@example.com/foo/bar
// https://me:xxxxx@example.com/foo/bar



Links:
[1] https://go-review.googlesource.com/c/go/+/207082/
источник
2020 April 16
Go на двоих
Note #65: новые темплейты в Go плайграунде!

* тесты
* поддержка нескольких файлов включая go.mod!
* можно напечатать картинку

https://play.golang.org
источник
2020 April 20
Go на двоих
Note #66: Go плайграунд теперь исполняет код в multi-threaded linux контейнере
   
Если у вас есть необходимость в демонстрации многопоточного кода на Go, который использует несколько горутин и которые, в свою очередь, используют один поток (thread) операционной системы или несколько потоков (threads), которые используют разные ядра. В общем теперь можно изучать go параллелизм в плайграунде 🙌

package main

import (
 "fmt"
 "runtime"
)

func main() {
 fmt.Printf("GOOS[%s] GOARCH[%s] GOMAXPROCS[%d] NumCPU[%d]", runtime.GOOS, runtime.GOARCH, runtime.GOMAXPROCS(0), runtime.NumCPU())
}
// OOS[linux] GOARCH[amd64] GOMAXPROCS[8] NumCPU[8]


P.S. объяснение от Брэда Фицпатрика:
Это стало возможным после того, как удалили поддержку Native Client (GOOS=nacl) в Go 1.14, и теперь go плайграунд запускается с помощью gVisor.
https://github.com/golang/go/issues/25224
https://github.com/golang/playground/commit/4d362417fd14b0b8349150cb28c3e8f2e756932e
источник
2020 April 26
Go на двоих
Note #67 What's coming in Go 1.15

Daniel Martí aka @mvdan_ недавно выступал на онлайн конференции "Go Remote Fest" с докладом: "What's coming in Go 1.15"!

Слайды его доклада можно найти по ссылке [1] или

Top 5 изменений:
- slightly smaller binaries (0.2% но все же =)
- new linker (еще WIP но можно ужно читать/смотреть [2]
- embed tzdata with time/tzdata https://github.com/golang/go/issues/38017
- add testing.TB.TempDir https://github.com/golang/go/issues/35998
- add testing.T.Deadline https://github.com/golang/go/issues/28135

Links:
- [1] https://docs.google.com/presentation/d/1veyF0y6Ynr6AFzd9gXi4foaURlgbMxM-tmB4StDrdAM/edit#slide=id.g840eaeb4b4_0_99
- [2] https://docs.google.com/document/d/1D13QhciikbdLtaI67U6Ble5d_1nsI4befEd6_k1z91U/view
источник
2020 June 22
Go на двоих
Note #68: The Rules of Optimization Club

1. You do not optimize.
2. You do not optimize, without measuring first.
3. When the performance is not bound by the code, but by external factors, the optimization is over.
4. Only optimize code that already has full unit test coverage.
5. One factor at a time.
6. No unresolved bugs, no schedule pressure.
7. Testing will go on as long as it has to.
8. If this is your first night at Optimization Club, you have to write a test case.

from https://wiki.c2.com/?RulesOfOptimizationClub
источник
2020 July 11
Go на двоих
Note #69: Debugging concurrency programs in Go

Slides of my talk: "Debugging concurrency programs in Go" from @GoWayFest

https://bit.ly/2C0vJOG
источник
2020 August 12
Go на двоих
Note #70: eBPF and golang

Extended
BPF has a new homepage: https://ebpf.io #bpf #ebpf 🎉

Extra links:
- go binding for bcc tools https://github.com/iovisor/gobpf
- interesting article from Brendan Greg about golang bcc/BPF function tracing http://www.brendangregg.com/blog/2017-01-31/golang-bcc-bpf-function-tracing.html
источник
2020 August 17
Go на двоих
источник
2020 August 18
Go на двоих
TIL: go get -x

If you need to run go get with debug info, it can surprise you because there is no -v or —verbose flag.
But we can run -x to show debug info TBH print the commands get eXecutes:

go get -x -u github.com/gliderlabs/ssh


P.S. -x also works with go mod.
источник
2020 August 19
Go на двоих
Note #71 The seven rules of a great Git commit message

1. Separate subject from body with a blank line
2. Limit the subject line to 50 characters
3. Capitalize the subject line
4. Do not end the subject line with a period
5. Use the imperative mood in the subject line
6. Wrap the body at 72 characters
7. Use the body to explain what and why vs. how

https://chris.beams.io/posts/git-commit/
источник
2020 August 20
Go на двоих
Note #72 TestMain in Go 1.15 testing package no longer calls os.Exit

tl;dr
- Go1.15 has been released
- Changed the implementation of the testing package so that TestMain no longer calls os.Exit
- It is realized by changing the implementation of testing.M and modifying the template of the main function generated by go test.

Found interesting article with great examples of changes between 1.14 and 1.15 -> https://qiita.com/hgsgtk/items/40e63150affed01f6573

TIP: right click translate into English.
источник
2020 August 24
Go на двоих
Визуализация нового пропозала про дженерики с отличными примерами от Владимир Вивьен

https://twitter.com/vladimirvivien/status/1297595414590427142?s=21
источник
2020 October 12
Go на двоих
TIL: that "fallthrough" ignors the next "case" condition.
This code will print "one" and "two".

package main

import (
 "fmt"
)

func main() {
 a := 10
 switch {
 case a < 20:
   fmt.Println("one")
   fallthrough
 case a < 10:
   fmt.Println("two")
 }
}


source https://twitter.com/yoavgo/status/1315622694554140673

P.S. я уже когда-то писал об этом тут https://t.me/golang_for_two/53
источник
2020 October 16
Go на двоих
Init time tracing coming to Go 1.16

GODEBUG=inittrace=1 prints a summary of execution time and memory allocation
information for completed package initialization work.

https://github.com/golang/go/commit/7c58ef732efd9bf0d0882bb95371ce1909924a75
источник
2020 November 19
Go на двоих
Experimental refactoring tool for Go from Russ Cox

no docs, but few interesting examples https://github.com/rsc/rf/tree/main/testdata

https://github.com/rsc/rf
источник
2020 December 17
Go на двоих
источник
2020 December 23
Go на двоих
Подъехали видео с последнего GopherCon 2020

https://www.youtube.com/playlist?list=PL2ntRZ1ySWBfUint2hCE1JRxRWChloasBhttps://www.youtube.com/playlist?list=PL2ntRZ1ySWBfUint2hCE1JRxRWChloasB

Пишите в комментариях какой больше всего доклад понравился?
источник