Category: Go
-
Post Views: 31 1. In VS Code, Go reports an error: Main redeclared in this block. The reason is that there are multiple main functions in the directory. as shown in Figure 1 2. Reorganize an exercise directory structure scheme of A Tour of Go to ensure that each exercise can run go run main.go independently, and there will be…
-
Post Views: 42 1. Reference: Build a RESTful API (go.dev) with Go and Ginhttps://go.dev/doc/tutorial/web-service-gin— Go official tutorial for building simple web services with GIN. 2. Install Go. Docker Compose One-click startup (refer to Hyperf project). I want to ‘write a good configuration, a command starts the entire development environment’, which is most convenient to use docker-compose.yml, which is almost the…
-
Post Views: 65 1. Reference URL: https://github.com/unknwon/the-way-to-go_zh_en/blob/master/ebook/09.11.md . Test by browsing the page of http://localhost:8080/. Enter: http://www.destandaard.be in shorten this, and click: Give me the short URL. Loading until timeout. as shown in Figure 1 2. Check the terminal output and report an error: Runtime Error: Invalid memory address or nil pointer dereference. as shown in Figure 2 3. Check…
-
Post Views: 17 1. Invoke the following command in the terminal to install the API: go install google.golang.org/api/urlshortener/v1, error: cant load package: package google.golang.org/api/urlshortener/v1. as shown in Figure 1 2. Reference:https://github.com/googleapis/google-api-go-client/blob/master/GettingStarted.md. Invoke the following commands in the terminal to install the API: go get -u google.golang.org/api/urlshortener/v1, error: Package google.golang.org/api/urlshortener/v1: unrecognized import path “google.golang.org/api/urlshortener/v1”. as shown in Figure 2 3. Reference:https://www.shuijingwanwq.com/2019/12/28/3784/.…
-
Post Views: 14 1. Reference URL:https://www.shuijingwanwq.com/2020/07/02/4288/. Previously, the code file could only be placed below: C:\Users\Administrator\Go\Src. Put it in: E:\wwwroot\go\src will report an error. 2. Edit the environment variable – the user variable of Administrator – GOPATH, its original value is: C:\Users\Administrator\Go, create a new: E:\wwwroot\go. Its new value is: C:\Users\Administrator\Go;E:\wwwroot\go. as shown in Figure 1 3. Reference URL:https://github.com/unknwon/the-way-to-go_ZH_CN/blob/master/eBook/09.8.md. Compile…
-
Post Views: 15 1. Error in Go: package_mytest.go:5:2: cannot find package “.” in: E:\WWWRoot\Go\The-way-to-go\package\pack1. as shown in Figure 1 2. Check the code of pack1.go 3. Check the code of package_mytest.go 4. Check the environment variables – the user variables of the administrator – GOPATH, whose values are: C:\Users\Administrator\Go, as shown in Figure 2 5. Compile and install a package.…
-
Post Views: 15 1. Error in Go: package_mytest.go:5:2: cannot find package “.” in: E:\WWWRoot\Go\The-way-to-go\package\pack1. as shown in Figure 1 2. Check the code of pack1.go 3. Check the code of package_mytest.go 4. Check the environment variables – the user variables of the administrator – GOPATH, whose values are: C:\Users\Administrator\Go, as shown in Figure 2 5. Compile and install a package.…
-
Post Views: 15 1. The Go doc tool can only obtain the comments in ../go/src in the go installation directory. In addition, it can also be used as a local document to browse the web server. Enter godoc -http=:6060 on the command line and open it with a browserhttp://localhost:6060After that, you can see the page provided by the local document…
-
Post Views: 11 1. Refer to the Go guide, web server, write file: web-servers.go 2. Accesshttp://localhost:4000/When prompted: The website cannot be accessed, as shown in Figure 1 3. Run in PowerShell: go run web-servers.go, visit againhttp://localhost:4000/When, the output: hello!, as shown in Figure 2