Pitfalls Encountered in Go JSON Practice

During the development process using the Go language, the json package is often used for mutual conversion between JSON and structs. In the process, I encountered some areas that require extra attention, which I have documented below. Integer to Float Conversion Issue Suppose there is a Person structure that contains two fields: Age int64 and Weight float64. Now, let’s convert the Person structure to map[string]interface{} using the json package. The code is as follows: ...

December 24, 2018 · 5 min · Zhiya

User Authentication Practice Based on JWT + Refresh Token

HTTP is a stateless protocol, meaning once a request is completed, the server doesn’t know who sent the next request (the same IP doesn’t represent the same user). In web applications, user authentication and authorization are crucial, and there are multiple practical solutions, each with its own merits. Session-Based Session Management In the early development of web applications, most adopted session-based session management, which works as follows: ...

December 13, 2018 · 6 min · Zhiya

SSH Tunneling Through ngrok

ngrok To access a host using SSH, if you are on the same local network as the host or if the host has a public IP, you can connect directly using the SSH command with the host’s IP address. However, most companies and homes use local networks and cannot assign a public IP to each host within the network. In such cases, network tunneling is needed to connect to hosts within a local network from the outside. ...

December 10, 2018 · 2 min · Zhiya

Unicode and UTF-8

The concepts of Unicode and UTF-8 are fundamental and important, yet they are often overlooked. Character Set In computer systems, all data is stored in binary, and all operations are represented in binary. Human languages and symbols also need to be converted into binary form to be stored in computers, which necessitates a mapping table from human language to binary encoding. This mapping table is called a character set. ...

December 7, 2018 · 3 min · Zhiya

Understanding Golang's Time Structure

When you create and print a time object in Golang, you’ll see an output like this: 2018-10-26 14:15:50.306558969 +0800 CST m=+0.000401093 The initial part is easy to understand, representing the year, month, day, time, and timezone. But what does the last part m=+xxxx signify? Monotonic Clocks and Wall Clocks According to the documentation of Golang’s time package, the time structure in Golang stores two types of clocks: Wall Clocks and Monotonic Clocks. ...

October 26, 2018 · 4 min · Zhiya