Tag Archives: golang

[Solved] Error 1044: Access denied for user ‘syz-remote‘@‘%‘ to database ‘webapp‘

Error 1044: Access denied for user ‘syz-remote’@‘%’ to database ‘webapp’

Cause: I was testing the code of golang connecting to the database. I finally reinstalled MySQL and set up remote login, but this problem still occurred.

My SYZ-remote account is specially created for remote login. Therefore, unlike the root user, it does not have the due permission. We need to set its permissions in MySQL .

View MySQL account permissions through this code

mysql> SELECT host,user,password_expired,Grant_priv,Super_priv FROM mysql.user;
+-----------+------------------+------------------+------------+------------+
| host      | user             | password_expired | Grant_priv | Super_priv |
+-----------+------------------+------------------+------------+------------+
| localhost | root             | N                | Y          | Y          |
| localhost | mysql.session    | N                | N          | Y          |
| localhost | mysql.sys        | N                | N          | N          |
| localhost | debian-sys-maint | N                | Y          | Y          |
| %         | syz-remote       | N                | N          | N          |
+-----------+------------------+------------------+------------+------------+
5 rows in set (0.00 sec)

You can see that the permission of Grant_priv and Super_priv in syz-remote is N

We gave him authority

update mysql.user set grant_priv = 'Y', Super_priv='Y' where user = 'syz-remote';

Refresh it again

flush privilegs;

How to Solve Brew install golangci-lint Error

Brew install golangci lint reports an error

Installation command:

brew install golangci-lint

report errors:

Error: No such file or directory @ rb_sysopen - /Users/...-go-1.16.6.big_sur.bottle.tar.gz

reason:

Go version problem

go 1.16.5 is already installed but outdated

Solution:

install go first and then golangci lint

brew install go
brew install golangci-lint

How to Solve Client-go Mod Error

Error message:

E:\github\client-go>go mod tidy
go: finding module for package k8s.io/client-go/kubernetes
go: finding module for package k8s.io/client-go/tools/clientcmd
go: finding module for package k8s.io/apimachinery/pkg/apis/meta/v1
go: found k8s.io/apimachinery/pkg/apis/meta/v1 in k8s.io/apimachinery v0.22.2
go: finding module for package k8s.io/client-go/kubernetes
go: finding module for package k8s.io/client-go/tools/clientcmd
client-go imports
        k8s.io/client-go/kubernetes: module k8s.io/client-go@latest found (v1.5.2), but does not contain package k8s.io/client-go/kubernetes
client-go imports
        k8s.io/client-go/tools/clientcmd: module k8s.io/client-go@latest found (v1.5.2), but does not contain package k8s.io/client-go/tools/clientcmd

Solution:
always specify three files in the go.mod file

require (
    ...
    k8s.io/api v0.19.0
    k8s.io/apimachinery v0.19.0
    k8s.io/client-go v0.19.0
    ...
)

macbook golang zsh: exec format error

On the Mac computer, compile the code of golang. After the code is successfully compiled, execute it. An error is reported

exec format error

After a long time of investigation, I finally found the problem: my computer’s configuration of golang is as follows:

GOOS="linux"

After compiling, I run it on MacOS, so I report an error.

When you know where the problem is, it’s very easy to solve it. When compiling, the execution is as follows:

GOOS=darwin GOARCH=amd64 go build -o  http -v ./main.go

Quickly convert map to ordered array

    take out the key of map and put it into a slice s to sort and traverse, V: = range s, take the value: map [v] from the map and put it in the array in turn 0

    var err error
    msgs = make([]*configModel.SysMailMsg, len(cacheMap))
    keys := make([]int, len(cacheMap))
    
    i := 0
    for k, _ := range cacheMap {
       if keys[i], err = strconv.Atoi(k); err != nil {
          return nil, err
       }
       i++
    }
    sort.Ints(keys)
    mi := 0
    for _, v := range keys {
       var tmp configModel.SysMailMsg
       json.UnmarshalFromString(cacheMap[strconv.Itoa(v)], &tmp)
       msgs[mi] = &tmp
       mi++
    }

[Solved] panic: proto: duplicate enum registered: raftpb.EntryType

  Error information:

A future release will panic on registration conflicts. See:
https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict

panic: proto: duplicate enum registered: raftpb.EntryType

goroutine 1 [running]:
github.com/golang/protobuf/proto.RegisterEnum(0x2461722, 0x10, 0xc0002b29f0, 0xc0002b2a20)
	/user/local/gopath/pkg/mod/github.com/golang/[email protected]/proto/registry.go:104 +0x11f
github.com/coreos/etcd/raft/raftpb.init.0()
	/user/local/gopath/pkg/mod/github.com/coreos/[email protected]+incompatible/raft/raftpb/raft.pb.go:508 +0x52
make: *** [show] error 2

Solution: add to go.mod

replace go.etcd.io/etcd => github.com/coreos/etcd v3.3.10+incompatible

standard_init_linux.go:178: exec user process caused “no such file or directory”

Golang Docker Build runs an error after making the input
The problem arises because the environment in which you are compiling is different from the environment in which you are running, and may have dependencies on dynamic libraries
1. By default, go USES static linking and dynamic compilation is used in Docker’s Golang environment.
2. If you want to compile +alpine to deploy with docker, you can do so by disabling cgoCGO_ENABLED=0.
3. If you want to use cgo, make GCC statically compiled by go build --ldflags "-extldflags -static".
 
 
 
Reference: https://yryz.net/post/golang-docker-alpine-start-panic.html
 

Reproduced in: https://www.cnblogs.com/davygeek/p/10969434.html

Error: Could not locate Flask application. You did not provide the FLASK_APP environment variable.

Problem description:

Error: Could not locate Flask application. You did not provide the FLASK_APP environment variable.

why
The FLASK_APP environment variable is not set
To solve
Under the win10
Powershell: $env:FLASK_APP="main.py" remember to replace main.py with your own filename
Py main. Py CMD: set FLASK_APP=flasky.py
As opposed to PowerShell… 😈

Fatal error: MSpanList_Insert error when installing golang source code

Golang was originally used in version 1.9, but today wants to upgrade to the latest version 1.11. Encountered the following error

failed MSpanList_Insert 0x905000 0x9b51f3c97b8 0x0 0x0
fatal error: MSpanList_Insert
runtime stack:
runtime.throw(0x5e5cf0, 0x10)
    /home/travis/.gimme/versions/go1.6.linux.amd64/src/runtime/panic.go:530 +0x90 fp=0x7fff5fbff0b0 sp=0x7fff5fbff098
runtime.(*mSpanList).insert(0x865d08, 0x905000)
    /home/travis/.gimme/versions/go1.6.linux.amd64/src/runtime/mheap.go:933 +0x293 fp=0x7fff5fbff0e0 sp=0x7fff5fbff0b0
runtime.(*mheap).freeSpanLocked(0x865500, 0x905000, 0x100, 0x0)
    /home/travis/.gimme/versions/go1.6.linux.amd64/src/runtime/mheap.go:809 +0x4be fp=0x7fff5fbff148 sp=0x7fff5fbff0e0
runtime.(*mheap).grow(0x865500, 0x8, 0x0)

The Internet did not find a good solution, finally put GOROOT_BOOTSTRAP go1.9 installation directory to solve. (The default GOROOT_BOOTSTRAP is pointing to go1.4)

cd ~/go/src
GOROOT_BOOTSTRAP='~/go1.9' ./all.bash

Go get github.com/kotakanbe/go -Problems encountered in CVE dictionary Download

(QIANG)

recently installed vuls on centos, which is the reason for QIANG’s frequent situation. Therefore, document several problems encountered and solutions

1.github.com undownloadable issues

before the reference to reprint an article in the link: https://blog.csdn.net/Jesusons/article/details/104267286
at the end of the centos/etc/hosts add

151.101.72.133 assets-cdn.github.com
151.101.229.194 github.global.ssl.fastly.net

will solve the problem

2. Resolve unknown import path “golang.org/x/sys/unix” : unrecognized import path “golang.org/x/sys”

is still QIANG, so you can’t directly visit golang.org. Fortunately, since Go 1.11, the Go module package dependency management tool has been officially supported. As long as you start Go modules, you can download it smoothly.

启用 Go Modules 功能
export GO111MODULE=on
 配置 GOPROXY 环境变量
export GOPROXY=https://goproxy.io

put a download interface after solving these two problems

Golang gets the list of files under the folder

golang document it is easier to find a method is filepath. Walk, this method has a problem of the current directory is automatically recursive traversal subdirectory, in fact, we usually just want to get a directory file list below, does not need so much information, at the same time this method is much more complicated to write code, we have no need to do so.

if you simply want to get a list of files and folders under a directory, there are two easy ways to do

USES ioutil’s ReadDir method

package main

import (
    "fmt"
    "io/ioutil"
)

func main() {
    files, _ := ioutil.ReadDir("./")
    for _, f := range files {
            fmt.Println(f.Name())
    }
}

using filepath Glob method

package main    

import (
    "fmt"
    "path/filepath"
)

func main() {
    files, _ := filepath.Glob("*")
    fmt.Println(files) // contains a list of all files in the current directory
}