go install:no install location 是怎么回事?
命令行提示 go install:no install location for _/e_/aoapp/src/mymath windows ,GOPATH=E:\mygo;E:\goap...阅读全文
命令行提示 go install:no install location for _/e_/aoapp/src/mymath windows ,GOPATH=E:\mygo;E:\goap...阅读全文
先上代码,结果是什么? package main import ( "fmt" ) const ( i=1<
package mainimport "fmt"type Student struct { Name string}func TestType(items ...interface{}) { for k, v := range items { switch v.(type) { case string: fmt.Printf("type is string, %d[%v]\n", k, v) case bool: fmt.Printf("type is bool, %d[%v]\n", k, v) case int: fmt.Printf("type is int, %d[%v]\n", k, v) case float32, float64: fmt.Printf("type is flo...阅读全文
管理员方式打开cmd cd gopath 手动go get,重启vs即可看到代码提示:go get github.com/mdempsky/gocodego get github.com/uudashr/gopkgs/v2/cmd/gopkgsgo get github.com/ramya-rao-a/go-outlinego get github.com/acroca/go-symbolsgo get golang.org/x/tools/cmd/gurugo get golang.org/x/tools/cmd/gorenamego get github.com/cweill/gotests/...go get github.com/fatih/gomodifytagsgo get gi...阅读全文
在开发中,我们经常会遇到一个nil值不等于nil,先看一下下面这个例子 type itest struct { a string } func printA() *itest{ return nil } func main() { var i interface{} = printA() fmt.Printf("i is nil %v, i = %v", i == nil, i) } 最后输出结果是 i is nil false, i =
golang中有一条代码规范检查: if block ends with a return statement, so drop this else and outdent its block 例如以下代码: else处会提示: if block ends with a return statement, so drop this else and outdent its blockgo-lint if k8serrors.IsNotFound(err) { c.deletePodQueue.Add(key) return } else { klog.Errorf("failed to get statefulset %v", err) return } 网上搜索有部分不太正确的解释或者修改...阅读全文
Golang: 思路:回到动态规划,使用二维数组,dp[i][j]表示前i、j位能否匹配 代码如下: func isMatch(s string, p string) bool { dp:=make([][]bool,len(p)+1) for k,_:=range dp{ dp[k]=make([]bool,len(s)+1) } dp[0][0]=true for i:=1;i<=len(p);i++{ if p[i-1]!='*' { dp[i][0]=false }else{ dp[i][0]=dp[i-2][0] } } for i:=1;i<=len(s);i++{ dp[0][i]=false } for i:=1;i<=len(p);i++{ for j:=1; j<=len...阅读全文
Golang: 思路:BFS做层次搜索 代码如下: func isCousins(root *TreeNode, x int, y int) bool { //表示x,y节点的父节点 var pars []int if root!=nil{ queue:=[]*TreeNode{root} //标记位,当出现x,y值时增加1 for len(queue)!=0{ flag:=0 level:=len(queue) for i:=0;i
package main import "fmt" type Student struct { Name string } func TestType(items ...interface{}) { for k, v := range items { switch v.(type) { case string: fmt.Printf("type is string, %d[%v]\n", k, v) case bool: fmt.Printf("type is bool, %d[%v]\n", k, v) case int: fmt.Printf("type is int, %d[%v]\n", k, v) case float32, float64: fmt.Printf("type is...阅读全文