2024/03/03
golang,string,containsAny,
2023/10/12
postgres, golang , sqlx, placeholder, in
sql: where some_id = any(:some_name)
golang, sqlx:
" some_name" : pg.StringArray([]string )
2023/07/06
vscode ,gvm ,GOROOT
gvm install go19.2
gvm list
gvm use go19.2 --default
=>GOROOT、GOPATH will be set by gvm automatically
vsCode will use the go defined by $GOROOT
2022/12/15
golang option pattern
- golang option pattern
2022/12/14
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 --
2020/10/16
golang sha256
package main
import (
"fmt"
"crypto/sha256"
)
func main() {
//saltで値変わるね
salt:="test"
hash := hmac.New(sha256.New, []byte("1"))
hash.Write([]byte(salt))
fmt.Printf("%x\n", hash.Sum(nil))
}
goplaygroud でやりました。
2020/05/29
golang var is nil
import (
"fmt"
)
func main() {
var stringArr []string
//true
fmt.Println(stringArr==nil)
// zero
fmt.Println(len(stringArr))
}
2019/12/18
golang gorm update when record not exist
have to check RowsAffected .
the same as delte
query := db.Model(r).Updates(something) if query.Error != nil { return query.Error } if query.RowsAffected == 0 { return gorm.ErrRecordNotFound }
query := db.Delete(&something{ID: ID}) if query.Error != nil { return query.Error } if query.RowsAffected == 0 { return gorm.ErrRecordNotFound }
2019/11/19
2019/09/02
golang validation array size
gte
ids []int `json:"ids,omitempty" binding:"required,gte=1"`
2019/06/25
gvm change gopath
gvm pkgset list
gvm pkgenv xxx
edit it
gvm pkgset use xxx
2019/03/27
gin,appengine,graphql test
gin+GAE+graphql のテスト下記で行けった。
appEngineTestInstance
->instance.NewRequest
gin.Context(request)
context.Set(key value)
```
ins, _ := aetest.NewInstance(nil) req, _ := ins.NewRequest("", "", nil) var context *gin.Context context = &gin.Context{Request: req} b, _ := json.Marshal(x.y{z: "1"}) context.Set("key", b)
2019/03/05
Removing packages installed with go get
$GOPATH/src
and the package file under $GOPATH/pkg/<architecture>
, for example: $GOPATH/pkg/windows_amd64
.example
go get github.com/golang/mock/mockgen
go clean -i github.com/golang/mock/mockgen
The -i flag causes clean to remove the corresponding installed
archive or binary (what 'go install' would create).
The -n flag causes clean to print the remove commands it would execute,
but not run them.
The -r flag causes clean to be applied recursively to all the
dependencies of the packages named by the import paths.
The -x flag causes clean to print remove commands as it executes them.
不知道安装的packagePath的话,找一下$GOPATH/pkg/windows_amd64啥的
2019/02/21
golang pointer compare
nil