Quickly editing Go struct tags under vim

I have written a previous article How to configure Vim’s Golang development environment. Go language jump completions use NeoVim’s built-in lsp functionality, so there is no need to integrate additional plugins. However, lsp does not seem to support adding or modifying tags to structs. My colleagues in the group started tinkering with it, and they found a small plugin developed in lua and introduced it to me. I thought about

How to Configure Golang Development Environment for Vim

Today we will introduce you how to configure Go development environment under Vim. If you are interested, you may want to give it a try. System Dependencies Before we start, we need a handy terminal emulation software. There are many such programs, but make sure to choose one that supports utf-8 encoding and 24-bit true color. Here I recommend. linux platform st macos platform iTerm2 window platform Windows Terminal There

Go Language Generic Design

After several years of work, the generic feature is finally going to follow the 1.18 release. This is a milestone. Considering that the original design document of Go generic is rather difficult and has a messy structure, I’ll compile my understanding into a document and share it with you today. Since there is a lot of content and my own understanding of the English design document is limited (especially the

Go Language Generics Example

Slicing Operations Functions like Map/Reduce/Filter are often used in functional programming. Because of generics, we can also write Map/Reduce/Filter functions that can be adapted to any type 😂. All three of these functions are used to process sliced data, so Go officially wanted to provide a standard slices package. But it’s subject to Rob’s objection, so it has to go under exp package underneath. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 // The slices package implements a series of slicing algorithms.

Basic usage of std::thread in C++

C++11 introduces std::thread to make it easier to create and manage multiple threads, and this note briefly documents my learning process. This note is a brief record of my learning process, including the management of thread creation and related usage in classes. requirement In order to use std::thread we need to add <thread> as a header file, and if we use cmake for project compilation management, we need to add

Enable Tab Search on your own blog

Chrome has a feature where you can enter a domain name in the address bar and press the Tab key to enter a search. This makes it easy to search for a site’s content. This feature is called Tab to Search. Of course, not every site supports it, as the search interface varies from site to site. However, this feature is not an adaptation of Chrome for well-known sites, but is implemented through an open standard OpenSearch description format .

Passing file descriptors between processes via UNIX domain sockets

Linux provides a series of system calls that allow us to pass file descriptors between processes. Instead of simply passing the file descriptor, which is a 32-bit integer, we actually pass the file handle to the target process so that it can read and write to the file. Now suppose process B wants to send a file descriptor to process A. Let’s see how to do that. 1. UNIX domain socket To pass file descriptors, you need to establish inter-process communication.

Promise and Deferred

1. Introduction In this article I want to discuss Promise in JavaScript and Deferred in Python Twisted (Deferred is also available in jQuery, and the idea is the same). They’re interesting, and a bit complicated. They played an important role in web programming before concurrency was widely used. Before that, let’s take a look at some basic concepts. 2. Starting with the request Requests and responses When we do network programming, we always use request and response .

Distributed Hash Table (DHT) and P2P technologies

1. Introduction I believe there is no one who has not used P2P technology. BT seeds and magnetic links are the most common P2P technologies. With P2P technology, files are no longer stored centrally on one server, but are distributed among users’ nodes, each of which is a provider and a user of the service. Such a system has high availability, so that the whole service will not be unavailable due to the downtime of one or two machines.

Why there are no more global variables in Lua 5.3

I’ve been using Lua 5.1 in the past, and I don’t know much about _ENV in Lua 5.3. Recently, I used Lua 5.3 in a new project, so I looked into it. This article summarizes the meaning of the environment and global variables in Lua 5.3, _ENV and their usage. Types of Lua variables Lua variables can be classified as local, upvalue and global variables. Anyone who has used Lua a lot should be familiar with it, as an example:

Gzip format and DEFLATE compression algorithm

1. Introduction When you type tar -zcf src.tar.gz src, you can package all the files under src into a tar.gz format. Here “tar” is the archive format, which combines multiple files into a single file, and “gz” refers to the gzip compression format, which uses the DEFLATE algorithm to compress. As the most widely used lossless compression algorithm, how does DEFLATE work and what are the principles behind it? In this article, we will discuss this issue.

Build HTTPS service for free with Cloudflare

Cloudflare proxy HTTPS certificate is too expensive, a wildcard domain name certificate a year to spend at least a couple of thousand. So how to meet the needs of the general public to build a website? Cloudflare is a very good choice. Cloudflare is a CDN provider, can provide reverse proxy for the site. It does this by resolving the domain name to Cloudflare’s server (or proxy), and then the browser uses Cloudflare’s certificate to establish an SSL connection with the proxy; then the proxy will establish an SSL connection with the target server using a self-signed certificate, and the next data are forwarded by the proxy.

Parsing syntax using LPeg

LPeg is a pattern matching library for Lua. When I was first introduced to LPeg, I thought it was just another form of regular expression; I found out that it is much more powerful than regular expressions, and can easily match complex patterns that are difficult to match with regular expressions, and even parse syntax. In fact, LPeg is Parsing Expression Grammars for Lua, which is designed to parse grammars. LPeg makes it easy to parse all kinds of grammars, for example in 400 lines of code parsing Lua source code into abstract syntax trees.

An interesting problem with the Lua next function

Anyone familiar with Lua knows that Lua allows you to modify and delete elements in a for ... pairs loop. pairs` loops to modify and delete elements in a table. There is nothing wrong with the following code: 1 2 3 4 5 6 local t = {a = 1, b = 2, c = 3} for k, v in pairs(t) do if v == 1 then t[k] = nil end end However, if we delete elements and add new elements while traversing, there will be a problem.

Implementing a Socks5 Secure Proxy with Go

I recently finished reading The Go Programming Language , and wanted to write something to practice. Go is more suitable for writing server software, and before that I learned Socks5 protocol, so I decided to write a Socks5 proxy server. The basic function is finished, part of the idea is referred to ginuerzh/gost. I named it Subsocks, sub- meaning under … (similar to “subway”). The project Repository is here: lyuhuang/subsocks. Here’s an introduction and a brief summary of its implementation.

Explaining the principle and implementation of KCP protocol

1. Introduction KCP is a fast and reliable ARQ (Automatic Repeat-reQuest) protocol that uses a different automatic retransmission policy than TCP and has a lower network latency than TCP. In practice, KCP over UDP is often used instead of TCP for online games and audio/video transmission. The implementation of KCP is short and concise, which is good for learning. The ARQ mechanism of KCP is similar to TCP, but some

Go sets up socket port multiplexing

We know that, in general, TCP/UDP ports can only be bound to one socket. When we try to listen to a port that is already listened to by another process, the bind call fails and errno is set to 98 EADDRINUSE. This is also known as port occupation. 1 2 3 4 5 6 7 8 9 10 int fd1 = socket(AF_INET, SOCK_DGRAM, 0); int fd2 = socket(AF_INET, SOCK_DGRAM, 0); struct sockaddr_in addr = {0}; addr.

Automatic generation of Lua hot update code

One of the main reasons why game servers use Lua is that it is easy to hot update. Even if the server is running, you can rewrite some of its functions for hot update purposes by simply having it execute a piece of code. For example, the module app has a function foo 1 2 3 4 5 6 7 local M = {} function M.foo(a, b) return a + b end return M If we want to hot change foo to multiply a and b, we just need to have the server load and run the following code:

Jump Consistent Hash Algorithm

In this article we discuss the Jump Consistent Hash algorithm, a minimalist and efficient consistent hashing algorithm. Hashing and Consistent Hashing A hash function, or hash function, maps the elements of a large definition field into a small finite value field. The elements in the value domain are sometimes called buckets, and the size of the value domain is also referred to as the number of buckets. MD5 is a common hash function that maps data of any size (the larger definition field) into a 16-byte hash (the smaller finite value field).

Network Digital Authentication

This article mainly wants to talk about one topic - authentication. That is, how to confirm that this data is sent by this person? User Password To solve this problem, let’s look at one of the simplest solutions - the use of passwords. Usually, to prove a person’s identity on the Internet, something private and unique about that person is needed. For example, in many places, if you provide your user name + password, you can be sure that the person is you (note: password management, strong password settings, password leaks, password cracking and password cajoling are not in this article), that is, the password is a very private matter, we can assume that only one person in the world knows this matter, so We can assume that only one person in the world can know the password, so that when the person has provided the correct password, we can authenticate the person.