Tag Archives: group

Error response from daemon: OCI runtime exec failed: exec failed: container_linux.go:345:

        An error was reported when using docker to enter the specified container today. The screenshot of the error is as follows:

        After careful verification, the command is correct, but it can’t get into the container. After checking the data, it is realized that there is a problem with the docker. It can be understood in combination with the error report:

Error response from daemon: OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown

        The above is complete error reporting information, of which the key information is as follows:

"/bin/bash\": stat /bin/bash: no such file or directory": unknown

        That is, there is no directory/bin/bash, so an error will be reported when you want to enter the container according to the initial command.

        You can enter by using the following command. The screenshot is as follows:

docker exec -it mqtt /bin/sh

      Perfect solution, record notes!

 

How to Solve golang test Error: # command-line-arguments [command-line-arguments.test]

Project scenario:

xxx.go xxx_unit test and code of test.go are open. The code is not in gopath and the project root set by idea.

Background:

Gopath:/users/ZYJ/go project root:/users/ZYJ/study/demogo source file:/users/ZYJ/study/demo/go/SRC/xxx_ test.go


Problem Description:

xxx.go xxx_test.go is stored separately   xxx_test.go compilation error

command-line-arguments [command-line-arguments.test]

Cause analysis:

Go test XXX executed by golang IDE_test.go runs as file by default and does not import dependent files. You need to actively import dependencies

Usually: the project is in gopath or project root directory, and the dependency can be found normally


Solution:

go test -v xxxx.go xxxx_test.go

Golang ide multiple selections for quick operation

How to Solve Docker Run Error: standard_init_linux.go:219: exec user process caused: exec format error

Use MAC M1 build image to run on Linux and report standard_ init_ linux.go:219: exec user process caused: exec format error

The main reason for this problem is that golang compilation cannot cross platform, that is, different systems or different CPU cores will cause this error. The golang code compiled under Linux arm cannot be run under Linux x86; Similarly, the image of a project with golang code cannot cross platform. The solution is very simple. When building, add the — platform Linux/AMD64 parameter

docker build --platform linux/amd64 -t tag .

[Solved] Go language gob serialization pointer cannot be addressed Error

1. Error description

An error occurs when using gob serialization: gob: addressable value of type * big. Float

Scenario:

Serializing a data structure contains a map field, where value is the big. Float structure type

type SideBlock {
  ...
  Varphi map[string]big.Float
  ...
}


func (b *SideBlock) Serialization() []byte {
	var res bytes.Buffer
	encoder := gob.NewEncoder(&res)
	err := encoder.Encode(b)
	if err != nil {
		logger.Error("Serialization err : ", err)
	}
	return res.Bytes()
}

Go version: go version go1.16.5 Darwin/arm64

OS: Mac OS BigSur 11.5.2

2. Error reason

The answer is found in issue:

He has a problem using URL. URL as the key of map

The problem lies in the pointer receiver of marshalbinary . If we want to use this structure as a key or value, we need to implement the marshalbinary method for special fields

personal understanding: when a map field of a structure has another structure instead of a pointer to the structure, it is a copy of the structure rather than itself during serialization, so it is difficult to address </ font>

3. Solution

Method 1:

https://play.golang.org/p/dK7SsqahtAd

package main

import (
	"encoding/gob"
	"fmt"
	"io/ioutil"
)

type T struct {
}

func (t *T) String() string { return "" }

func (t T) MarshalBinary() (text []byte, err error) {
	return []byte(t.String()), nil
}

func main() {
	m := make(map[T]int)
	m[T{}] = 0
	e := gob.NewEncoder(ioutil.Discard)
	fmt.Println(e.Encode(m))
}

Method 2:

Change big. Float into a pointer, that is, the field becomes varphi map [string] * big. Float

$GOPATH/go.mod exists but should not

The reason for this is that after the module support is enabled, it cannot be connected with the

G

O

P

A

T

H

common

Save

,

place

with

hold

term

order

from

Gopath coexists, so the project from

Gopath coexists, so you can remove the project from gopath

Reproduced at: https://my.oschina.net/pokdars/blog/2222300

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

The use of makefile in GoLand under Windows

Install chocolate

The official website is very clear. Just refer to the official website for download

Install make

To execute the makefile file, you need to use make, and install make by using chocolate (note that you also need to use the administrator identity)

 choco install make

Change GoLand settings

At this point, you can use the make instruction to execute the makefile file

[Solved] #command-line-arguments .\main.go:5:4: no new variables on left side of :=

# command-line-arguments
.\main.go:5:4: no new variables on left side of :=
package main
import “fmt”
func main(){
var b int;
b := 1;
fmt.Println(b);
}

The correct way to write it: remove the : or add a new variable
package main
import “fmt”
func main(){
var b int;
b,a := 1,2;
fmt.Println(b,a);
}
// No compile error is generated at this point because a new variable is declared, because := is a declaration statement

 

Go declares that the local variable does not use command line arguments. Main. Go: 4:6: a declared but not used

Declaring global variables that are not used does not report errors
# command-line-arguments
.\main.go:4:6: a declared but not used
package main
import “fmt”
func main(){
var a string=”hhh”;
var b,c int =1,2
fmt.Println(b,c);
}
Correct writing style:
package main
import “fmt”
func main(){
// var a string=”hhh”;
var b,c int =1,2
fmt.Println(b,c);
}