Golang Generics in HTTP API

Golang started to support generic types from version 1.8 start, and I believe many people are in the same wait-and-see state as me. Now that Golang has been released to version 1.19, I think it’s a good idea to give it a try. Example of adding two numbers together One of the most common examples of previous calls for Golang to introduce generics is a scenario like adding two numbers together.

How to implement hot reload config

Sometimes some processes must inevitably have the problem that restarting is too costly. For example, there are processes with long connections where restarting will disconnect and then all clients will need to reconnect, or processes that already have a lot of content cached in memory that will need to be rewarmed if restarted. But then there are configurations where we want to modify the configuration of the process without restarting it.

Compiling Rust projects with Nix

Rust projects are generally managed with Cargo, but it has the disadvantage of having to recompile all dependencies once per project, taking up a lot of hard disk space, and not being able to share the build cache across projects. After some research, there are several Nix-based Rust build tools: cargo2nix: https://github.com/cargo2nix/cargo2nix carnix: no longer updated crane: https://github.com/ipetkov/crane crate2nix: https://github.com/kolloch/crate2nix naersk: https://github.com/nix-community/naersk nocargo: https://github.com/oxalica/nocargo I’ll try out each of these tools below.

From .go text files to executable files

Go is a compiled language, and the *.go text files we write are called source files, and the contents of the source files are our source code. For the source code to run on the target machine, it must be compiled into a binary machine code file, or executable, that is directly recognized by the operating system using the Go compiler (abbreviated gc, which stands for Go compiler). The operating

volatile in C

When learning C language there is a strange keyword volatile, what exactly is the use of this? volatile and the compiler First look at a piece of code like this. 1 2 3 4 5 6 7 int busy = 1; void wait() { while(busy) { ; } } Compile it and note that O2 optimization is used here: Let’s take a closer look at this generated assembly. 1 2 3 4 5 6 7 8 9 wait: mov eax, DWORD PTR busy[rip] .

void_t in C++17

I recently discovered an interesting feature: void_t. void_t is a new feature introduced in C++17, and its definition is simple (some compiler implementations may not be, but they are broadly similar). 1 2 template< class... > using void_t = void; It looks simple, but with SFINAE it can be very useful in template metaprogramming. For example, determining at compile time whether a class has a certain type using. 1 2 3 4 5 6 template <class, class = std::void_t<>> struct has_type : std::false_type {}; template <class T> struct has_type<T, std::void_t<typename T::type>> : std::true_type {}; For example, to determine if a member is present.

DNS Query Principle Explained

The IP address of the domain name is obtained by DNS lookup in order to access the website. So, how exactly does a DNS lookup work? This article describes the steps behind it in detail with examples. 1. DNS Servers The IP addresses corresponding to domain names are stored in DNS servers. When we enter a domain name, the browser will automatically send a request to the DNS server in the background to get the corresponding IP address.

Install and use tftp server on Centos.

1 Installation If the network is available, you can install it directly via yum. 1 yum install tftp-server You can also download the rpm package first and then install it, download at http://rpmfind.net/linux/rpm2html/search.php?query=tftp-server Then install. 1 rpm -ihv tftp-server-0.49-8.el6.x86_64.rpm After installation, you can find an additional in.tftpd file in the /usr/sbin directory. 1 2 $ ls /usr/sbin/in.tftpd /usr/sbin/in.tftpd 2 Configuration in.tftpd is managed through the xinetd service. /etc/xinetd.conf stores the default configuration of all services managed by xinetd, and also the default configuration of tftpd.

Go mod add gitlab private repository

1. set env 1 2 3 4 5 6 7 8 9 10 11 # Set the git address of the private repository go env -w GOPRIVATE="git@gitlab.xxx.cn" # Allow setting unsecured access to a repository that can be requested to an http address after configuration go env -w GOINSECURE="gitlab.xxx.cn" # Set the request to this address without a proxy, i.e. GOPROXY go env -w GONOPROXY="gitlab.xxx.cn" # Set not to verify the signature of sum packages go env -w GONOSUMDB="gitlab.

Go Assembly Overview

Direction The plan9 assembly operand direction is the opposite of the intel assembly direction, plan9 is left to right and intel is right to left. 1 2 3 4 5 // plan9 MOVQ $123, AX // intel MOV RAX, 123 Stack push and pop In plan9, there is no PUSH POP instruction for stack operation, but SUB and ADD respectively. SP is the top of stack pointer, which corresponds to BP bottom of stack pointer, usually only need to operate SP pointer to complete push and pop operations, so BP pointer is not used much.

Customizing images with Dockerfile

This article is a detailed explanation of Docker custom images, how to build your own Docker images, and the Dockerfile instructions. I. Using Dockerfile to customize images 1.1, Dockerfile customization image Customization of images is actually customizing the configuration and files added to each layer. If we can write a script for each layer to modify, install, build, and operate the commands, and use this script to build and customize the image, the problem of not being able to repeat, the problem of transparency of image construction, and the problem of volume will all be solved.

Hashcorp Vault Basic Tutorial

How do we manage the large amount of Secret information in our work? (For example, my project involves the storage of secret keys and passwords for OpenSSH, as well as the regular rotation and external invocation of this) Solidified in a configuration file, stored in a server file or Database stored as code on a git private repository, with strict access rights to the repository Hosted on a public cloud

Write your own WebAssembly modules using C and Emscripten

Like JavaScript, WebAssembly is a programming language that can be run in a browser, but it is more equivalent to assembly language. wasm files consist of binary bytecode (which can also be converted to an assembly-language-like text format for viewing) and can be generated from C/C++, Rust, and other compiled and executed programming languages. Of course, WebAssembly is also cross-platform, and compiled wasm files can be run in browsers on

What does Python 3.9 bring?

I’ve been learning about the new features that each new Python release brings that are helpful to developers. Today we’ll start with Python 3.9, which is very middle-of-the-road and doesn’t have many valuable changes. Add union operators to dict In PEP 584 - Add Union Operators To dict it is proposed to add 2 operators to dict, | and |=. There are two common ways to merge 2 dictionaries in the past:

Certificate management tools in Kubernetes - cert-manager

This article introduces cert-mangager, which is somewhat similar to certbot, but the difference is that it works in Kubernetes. cert-manager is an automated certificate management tool that automates the issuance and management of digital certificates from various sources and for various purposes in a Kubernetes cluster. It will ensure that certificates are valid and automatically renew them at the appropriate time. Note: The object managed by cert-manager is “certificate”. If

2022 Go Ecosystem rpc Framework Benchmark

This test was conducted for five common rpc frameworks: rpcx, one of the earliest Go ecosystem microservices frameworks, used by Sina, Good Future, etc. kitex, bytedance’s microservices framework arpc: a performance rpc framework by lesismal grpc: a Google-initiated open source rpc framework that supports cross-language and is widely used. The system is based on HTTP/2 protocol transport and uses Protocol Buffers as the interface description language. standard library of rpc/std_rpc: Go standard library comes with the rpc framework, currently in a maintenance state The latest version of each framework is used for testing:

Why floating-point arithmetic is inaccurate

Verify 1 2 3 4 >>> 0.3-0.2 0.09999999999999998 >>> 0.2-0.1 0.1 Verify a little deeper First write the tool. Write a function to display 64-bit 8-byte binary data. 1 2 3 4 5 6 7 8 9 10 11 12 import struct def byte2bin(s, g=8): o = [] for i in range(0, len(s), g): sub = s[i:min(i+g, len(s))] o.append(' '.join((f'{c:08b}' for c in sub))) return '\n'.join(o) print(byte2bin(b'abcdefghijklmnopqrstuvwxyz')) The output is as follows.

Rust Pin Advanced

The last article on Pin was a shallow introduction to what Pin is all about and why it is needed, but it is still not enough to master that part of knowledge, so this article hopes to systematically sort out the knowledge points related to Pin, so I named the title “Rust Pin Advanced”. Pin API Anatomy To understand Pin in depth, it is essential to be familiar with all of its methods.

Pin and Unpin in Rust

On February 28, 2019, Rust version 1.33 was released, adding new pinning APIs, mainly including these. std::pin::Pin std::marker::Unpin std::marker::PhantomPinned impl !Unpin for T When I first encountered these concepts, I felt that they were particularly convoluted and difficult to understand thoroughly. There are also many articles on the Internet about Pin and Unpin, but I feel that they are not particularly clear. It’s also difficult to understand the std::pin module documentation directly.

Implement a simple RTSP server

In the previous article, the RTSP protocol itself was briefly introduced, and this time we will talk about how to implement a simple RTSP server. Live555 Live555 is a C++ media library that supports a wide range of media services protocols, streaming, receiving and processing audio and video data in a variety of audio and video encoding formats. It is also one of the few available libraries, and its code is rather cumbersome, but it is simple enough for most people to get started with, so it is perfect for practice and rewriting.