Failed to download golang toolkit
1 | $ go env -w GOPROXY=https://goproxy.cn |
cannot initialize 1 variables with 2
1 | input, _ := strconv.ParseInt(scanner.Text(), 10, 64) |
here the strconv
will return a set of two values, one for result and one for error exception, so we add the _
to catch the exception msg
difference between :=
and =
https://blog.csdn.net/hxpjava1/article/details/79865133
check and update go.mod
for all dependency
1 | $ go mod tidy |
this cmd will automatically download the missing dependency and update it to go.mod.
context
https://zhuanlan.zhihu.com/p/110085652
buffered channel
Buffered channels allows to accept a limited number of values without a corresponding receiver for those values.
Buffered channel are blocked only when the buffer is full. Similarly receiving from a buffered channel are blocked only when the buffer will be empty
1 | c1 := make(chan string, 1) // Buffered |
net/rpc usage
https://blog.csdn.net/raoxiaoya/article/details/109473904
mongo db
- collection: https://docs.mongodb.com/manual/core/databases-and-collections/
Collections are analogous to tables in relational databases
package xxx/middleware is not in GOROOT (C:\Program Files\Go\src\xxx\middleware)
not sure about how to fix it, but I just no longer saw same error happen in new project any more …
introduce package under same project
1 | project-1 |
Here I want to introduce func NewServer
into main.go
- define module for project-1
1
$ go mod init project-1 # under pwd /project-1
- name package name in
server.go
and make sure the func name is start with upper class letterhttps://segmentfault.com/q/10100000413902811
2
3
4
5package server
...
func NewServer() {
...
}
If your func is not started with upper class letter, go kit for vscode cannot detect the func and will show error like:Auto saving will remove your import package as it is considered not used.1
func not exported by package
- import to
main.go
btw, if you are introducing struct or func inside the same package, there’s no need to import, go ahead and use it directly.1
2
3
4
5import(
"project-1/server"
)
...
s := server.NewServer()
gin.Context
vs http.Request
& http.ResponseWriter
gin.Context
is encapsulated as the combination of http.Request
& http.ResponseWriter
https://juejin.cn/post/6844903830669262855
rsa encryt
https://zhuanlan.zhihu.com/p/384595092
gin.H
= map[string]interface{}
https://segmentfault.com/q/1010000017476060/a-1020000017486404
add, delete for go Array
Mainly use Slice
, see https://blog.csdn.net/youngwhz1/article/details/83026263