-
curl works but http.Get fails with error: dial tcp: lookup locahost on 127.0.0.53:53: server misbehaving
摘要:zzh@ZZHPC:/zdata/Github/mastering-go-expertise/stats_web/server$ go run . Ready to serve at :1234 zzh@ZZHPC:~$ curl localhost:1234/list d6 4 2.325000
阅读全文
-
Docker Compose - deploy stats_server
摘要:services: stats_server: image: stats_server container_name: stats_server restart: always ports: - 1234:1234 networks: - stats networks: stats: driver:
阅读全文
-
Dockerfile - build stats_server
摘要:FROM golang:alpine AS builder # Install git. # Git is required for fetching the dependencies. RUN apk update && apk add --no-cache git RUN mkdir $GOPA
阅读全文
-
Cobra - Flags are parsed in rootCmd.Execute()
摘要:root.go: func init() { rootCmd.PersistentFlags().BoolVarP(&enableLogging, "log", "l", true, "Logging information") fmt.Println("**********************
阅读全文
-
VSCode - gopls error
摘要:[Error - 5:36:50 PM] Request textDocument/semanticTokens/range failed. Message: semantictokens are disabled Code: 0 [Error - 5:36:50 PM] Request textD
阅读全文
-
VSCode - settings.json
摘要:{ "workbench.startupEditor": "none", "[go]": { "editor.insertSpaces": true, "editor.formatOnSave": false }, "editor.fontSize": 16, "terminal.integrate
阅读全文
-
Go - The log/slog package
摘要:package main import ( "fmt" "log/slog" "os" ) func main() { slog.Error("This is an ERROR message") slog.Debug("This is a DEBUG message") slog.Info("Th
阅读全文
-
Cobra
摘要:zzh@ZZHPC:/zdata/Github/mastering-go-expertise$ cd go-cobra/ zzh@ZZHPC:/zdata/Github/mastering-go-expertise/go-cobra$ cobra-cli init Error: invalid ch
阅读全文
-
Python - Arrays and Numpy Arrays
摘要:Most programming languages provide a data structure called arrays. In Python, array is a package and it is different from “core” python lists. The syn
阅读全文
-
Data Analytics
摘要:Types of Measurement Scales Data Analytic Process 1. Understanding the Business This step involves understanding the objectives and requirements of a
阅读全文
-
Python - debugging
摘要:Python provides a native debugger called Python debugger (Pdb). It is one of the default debuggers that come bundled with Python. What is the use of P
阅读全文
-
Python - exception
-
Python - import
摘要:Usage of Dot "." Operator in Relative Import In the above code, "..module4" represents that module4 is present in the parent folder to the current loc
阅读全文
-
Python - Meta Class
摘要:As part of metaprogramming, a metaclass is one of the most important concepts in Python. A Class in Python defines the functionality of its objects us
阅读全文
-
Python - class Method and static Method
摘要:The methods in a class are associated with the objects created for it. For invoking the methods defined inside the class, the presence of an instance
阅读全文
-
Python - Overloading
摘要:Object Oriented Programming (OOP) allows the programmers to add some additional functionalities to the operators and methods which have basic properti
阅读全文
-
Python - Name Mangling
摘要:Name mangling is the process of naming the variable using the prefix "__" (double underscore), which makes the variable can be accessed only by using
阅读全文
-
Functional Programming
摘要:Advantages and Disadvantages of Functional Programming
阅读全文
-
Python - Regular Expressions
摘要:re Package methods Character Class Regular expression with description
阅读全文
-
Python - Key Differences between the Single and Double Quotes
-
Python - String Format
摘要:>>> format_string=("%2f" %13.333222) >>> print(format_string) 13.333222 >>> format_string=("%2.3f" %13.333222) >>> print(format_string) 13.333 >>> nam
阅读全文
-
Python - Escape Characters
-
Python - Operator Precedence
摘要:>>> help() help> PRECEDENCE Operator precedence ******************* The following table summarizes the operator precedence in Python, from highest pre
阅读全文
-
Python - list keywords
摘要:>>> import keyword>>> keyword.kwlist['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'el
阅读全文
-
Go - scan
摘要:func getUserInput() { fmt.Print("Please give me your name: ") var name string // Scan scans text read from standard input, storing successive space-se
阅读全文
-
Shell - command line arguments
摘要:zzh@ZZHPC:~/.goenv/shims$ cat godoc #!/usr/bin/env bash set -e [ -n "$GOENV_DEBUG" ] && set -x program="${0##*/}" if [[ "$program" = "go"* ]]; then fo
阅读全文
-
Linux - set
摘要:zzh@ZZHPC:~$ help set set: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] Set or unset values of shell options and positional parameters. Ch
阅读全文
-
Go - How to remove a module
摘要:You can remove a module from go.mod using none as follows: $ go get github.com/rabbitmq/amqp091-go@nonego: removed github.com/rabbitmq/amqp091-go v1.8
阅读全文
-
RabbitMQ
摘要:docker-compose.yml: services: rabbitmq: image: 'rabbitmq:3.13-management' container_name: rabbitmq ports: - '5672:5672' - '15672:15672' environment: A
阅读全文
-
Go - websocket
摘要:server.go: package main import ( "fmt" "log" "net/http" "os" "time" "github.com/gorilla/websocket" ) var port = ":1234" var upgrader = websocket.Upgra
阅读全文
-
Go - semaphore
摘要:package main import ( "context" "fmt" "os" "strconv" "time" "golang.org/x/sync/semaphore" ) func worker(n int) int { square := n * n time.Sleep(time.S
阅读全文
-
Go - Receiving from a closed channel
摘要:Reading from a closed channel returns the zero value of its data type. However, if you try to write to a closed channel, your program is going to cras
阅读全文
-
Go - pflag and viper
摘要:pflag is a drop-in replacement of Go's native flag package. If you import pflag under the name "flag" then all code should continue to function with n
阅读全文
-
Zgo - Writing to a file
摘要:package main import ( "bufio" "fmt" "io" "os" ) func main() { buffer := []byte("Data to write\n") f1, err := os.Create("f1.txt") if err != nil { fmt.P
阅读全文
-
Go - Reading from /dev/random
摘要:The purpose of the /dev/random system device is to generate random data, which you might use to test your programs or, in this case, as the seed for a
阅读全文
-
Zgo - Read text files
摘要:package main import ( "bufio" "fmt" "io" "os" ) func lineByLine(file string) error { f, err := os.Open(file) if err != nil { return err } defer f.Clos
阅读全文
-
Zgo - go-sqlite3
摘要:package main import ( "database/sql" "fmt" "os" _ "github.com/mattn/go-sqlite3" ) func main() { // Connect or create a SQLite database db, err := sql.
阅读全文
-
Go - Order of execution
摘要:If there are multiple init() functions in a package, don't use in an init() function a global variable that is initialized in another init() function,
阅读全文
-
Go - The map[string]interface{} map
摘要:Remember that the biggest advantage you get from using a map[string]interface{} map, or any map that stores an interface{} value in general, is that y
阅读全文
-
Go - reflect
摘要:package main import ( "fmt" "reflect" ) type Secret struct { Username string Password string } type Record struct { Field1 string Field2 float64 Field
阅读全文
-
Zgo - maps
摘要:package main import ( "fmt" "maps" ) func delete(k string, v int) bool { return v%2 != 0 } func equal(v1 int, v2 float64) bool { return float64(v1) ==
阅读全文
-
Zgo - slices
摘要:package main import ( "fmt" "slices" ) func main() { s1 := []int{1, 2, -1, -2} s2 := slices.Clone(s1) fmt.Printf("%p\n", s1) fmt.Printf("%p\n", s2) s1
阅读全文
-
Go - Generics
-
Zgo - csv_data.go
摘要:package main import ( "encoding/csv" "log" "os" ) type Record struct { Name string Surname string Number string LastAccess string } var myData = []Rec
阅读全文
-
Go - Regular Expressions
-
Zgo - randInt, randString
摘要:package main import ( crand "crypto/rand" "encoding/base64" "fmt" mrand "math/rand" "strings" ) const ( // As we only want to get printable ASCII char
阅读全文
-
Zgo - custom_log.go
摘要:package main import ( "fmt" "io" "log" "os" "path" ) func main() { flag := os.O_APPEND | os.O_CREATE | os.O_WRONLY logFile := path.Join(os.TempDir(),
阅读全文
-
Zgo - which.go
摘要:package main import ( "fmt" "os" "path/filepath" ) func main() { args := os.Args if len(args) == 1 { fmt.Println("Please provide an argument!") return
阅读全文
-
Go - Using error variables to differentiate between input types
摘要:package main import ( "fmt" "os" "strconv" ) func main() { arguments := os.Args if len(arguments) == 1 { fmt.Println("Not enough arguments") } var tot
阅读全文
-
Go - Global Variables
-
Go - defer
摘要:由上可以看出,当return语句中有函数调用时,先执行return中调用的函数,再执行defer的语句。 用Ctrl+C中断程序运行时defer语句不会被自动执行。
阅读全文
|