- golang option pattern
2022/12/15
2022/12/14
what is good bulk insert
golang chunk
- chunk
big array goroutine
- https://qiita.com/tutuz/items/057452fbbe9a5ae26d37
2022/12/08
golang fmt %q
文字列を””で囲んで出力する。
これで実際の を””に表現して、わかりやすい
spannerのgolang clientで%qを使っている
It's just quite a strange decision made by Google here, to assume that the String()
function is only used for logging and it's ok to add quotes...
package main
import (
"fmt"
)
func main() {
str := "Gopherくん"
slice := []string{"g", "o", "h", "e", "r"}
integer := 12450
fmt.Printf("1:出力は %q となります。\n", str)
fmt.Printf("2:出力は %s となります。\n", str)
fmt.Printf("3:出力は %q となります。\n", slice)
fmt.Printf("4:出力は %s となります。\n", slice)
fmt.Printf("5:出力は %d となります。\n", integer)
fmt.Printf("6:出力は %q となります。\n", integer)
}
//1:出力は "Gopherくん" となります。
//2:出力は Gopherくん となります。
//3:出力は ["g" "o" "h" "e" "r"] となります。
//4:出力は [g o h e r] となります。
//5:出力は 12450 となります。
//6:出力は 'ア' となります。 (アのunicode の十進制は12345)
2022/12/07
spanner nullable data type golang
spanner nullable data type
var user User
db.First(&user)
db.Model(&user).Updates(User{Age: 18, Name: nil})
// 実行 SQL : UPDATE `users` SET `age` = '18' WHERE `users`.`id` = '1'
GORM のドキュメントを見ると以下のように書いてあったので、構造体で実行すると無視されてしまうようです。 When query with struct, GORM will only query with those fields has non-zero value,
that means if your field's value is 0, '', false or other zero values,
it won't be used to build query conditions,
go instal where ?
go install xxx..xxx
==>the location is ~/go/bin
so ,set the ~/go/bin to .bash_profiles 's PATH
go version
go help environment
```
GOBIN
The directory where 'go install' will install a command.
GOPATH
For more details see: 'go help gopath'.
GOROOT
The root of the go tree.
```
go help gopath
```
If the environment variable is unset, GOPATH defaults
to a subdirectory named "go" in the user's home directory
($HOME/go on Unix, %USERPROFILE%\go on Windows),
unless that directory holds a Go distribution.
Run "go env GOPATH" to see the current GOPATH.
```
go env GOPATH
==>~/go
go help install
````
usage: go install [build flags] [packages]
Install compiles and installs the packages named by the import paths.
Executables are installed in the directory named by the GOBIN environment
variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH
environment variable is not set. Executables in $GOROOT
are installed in $GOROOT/bin or $GOTOOLDIR instead of $GOBIN.
```
golang model
https://go.dev/play/p/B7ErJjt8JqU
-- go.mod --