1. echo Without Parameters
Displays the current state of echo: whether it is on or off. With Parameters
Parameter [on/off]: on turns on command echoing; off turns off command echoing. “Echoing” can be understood as repeating the display. Parameter message: Prints the content of message. @ before echo: Adding @ means the command itself will not be displayed; otherwise, the command itself will be shown. Parameter message > file: Writes the content of message to file, where > means clear and write.
...
1func interceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { 2 start := time.Now() 3 err := invoker(ctx, method, req, reply, cc, opts...) 4 logger.Infof("[gRPC] method=%s req=%v rep=%+v duration=%s error=%v", method, req, reply, time.Since(start), err) 5 if err != nil { 6 return err 7 } 8 9 return nil 10} In a gRPC interceptor, I wanted to add a check to determine if the server’s response is nil to avoid subsequent panic when accessing fields (I didn’t want to check every time).
...
1. Scenario When using YAML as a configuration file, it is often necessary to parse the configuration when starting a service. If the data structure of a field is modified, the service might panic immediately. Sometimes, we do not want the business to stop at this point and hope to replace it with a default configuration file.
1# cfg.yaml 2language: Golang 3animal: Dog 1type Cfg struct { 2 Language string `json:"language,omitempty"` 3 Animal string `json:"animal,omitempty"` 4} Under normal circumstances, the YAML file will be parsed successfully as follows:
...
1. Variable Declaration Variable declaration refers to informing the compiler about the type and name of a variable without allocating memory or initializing it. In Go, variable declaration is typically done using the var keyword.
1var x int In this example, x is declared as a variable of type int, but at this point, x is not assigned any initial value. Go will allocate memory for x and initialize it to the zero value of the int type (i.
...
TCP Protocol You need to establish two session windows - one as TCP Server and another as TCP Client for communication between them. Note that sometimes you may encounter bind() failure errors, which usually occurs when the specified port is already in use. You can use the previously mentioned cmd commands to check and resolve this issue.
UDP Protocol UDP doesn’t require handshaking connection. After clicking connect, simply specify the remote host and port to send and receive data.
...
kill 1$ kill pid # kill -15 pid default kill The system sends a SIGTERM signal to the corresponding program. When the program receives this signal:
The program stops immediately. The program stops after releasing its resources. The program may continue running. Most programs will release their resources before stopping after receiving the SIGTERM signal. However, some programs can perform other configurable actions upon receiving the signal. If the program is waiting for I/O, it may not respond immediately.
...
In the Go language, Map is implemented based on a Hash Table. The core idea of a hash table is to map a key to a storage location (bucket) using a hash function, enabling fast data lookup, insertion, and deletion. Basic Concepts Map Also known as a dictionary, hash table, or associative array, a map is a widely used data structure in computer science for storing key-value pairs, where each
...
OVS Network Architecture Open vSwitch is an open-source virtual switch that supports the OpenFlow protocol. It can be managed remotely by controllers through the OpenFlow protocol to achieve networking and interconnection for connected virtual machines or devices. Its main functions are:
Transmitting traffic between virtual machines Enabling communication between virtual machines and external networks OVS Internal Structure OVS has three core components:
ovs-vswitchd: The OVS daemon process, which is the core component implementing switching functionality.
...