Go Context Best Practices

Usage Scenarios There are three main usage scenarios for Context Passing timeout information, which is most used. Passing signals, used for message notification, handling multi-process communication Passing data, commonly used in the framework layer trace-id, metadata Let’s take an example of etcd watch to get a better understanding. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 func watch(ctx context.Context, revision int64) { ctx, cancel := context.

Android FFmpeg video decoding process and practical analysis

This article firstly introduces the main process and basic principle of decoding video with FFmpeg as the topic; secondly, it also describes the simple applications related to FFmpeg video decoding, including how to play video in a certain timeline order based on the original FFmpeg video decoding, and how to add the logic of seek when playing video. Besides, the article focuses on the details that may be easily missed

Jib builds Docker images efficiently

1. Preface Jib is a class library developed by Google to build Docker and OCI images of Java applications directly, provided as Maven and Gradle plugins. The best part is that it can be built without the Docker daemon, i.e. you don’t have to install the docker daemon on your computer! Although Spring Boot 2.3.0.RELEASE has already been released with the ability to build images, I couldn’t resist trying Jib.

The relationship between x86,x64,x86-64,amd64,arm instruction set architecture

There is no such thing as x32. x86 and x64 refer to the instruction set architecture of the CPU. Instruction set The instruction set can be understood as the hardware’s interface to the outside world. We run programs through the operating system scheduling, and the operating system then allows the hardware to compute. If you let the hardware compute, such as some addition and multiplication, loops and so on, you need the interface provided by the hardware, that is, the instruction set.

ref of component communication

The official react documentation describes it this way. Refs provide a way to allow us to access DOM nodes or React elements created in the render method. I. A simple example Let’s look directly at an example of ref usage. Here is a function component that creates a ref using useRef. 1 2 3 4 5 6 7 8 9 const App = () => { const myRef = useRef();

The difference between useEffect and useLayoutEffect

I. The execution process of useEffect and useLayoutEffect The first thing to note is that useLayoutEffect and useEffect are very similar and have the same function signature. The only difference is that useEffect is executed asynchronously, while useLayoutEffect is executed synchronously. When the function component is refreshed (rendered), the whole process of the component containing the useEffect runs as follows. component re-rendering is triggered (by changing the component state or

TypeScript generic development practices from a set perspective

Some time ago I drilled into How to master advanced TypeScript patterns this article. This is an earlier blog post by Pierre-Antoine Mills, author of ts-toolbelt. The article raises a challenging topic: How can TS write type support for collinear functions? I did some practice with the original article, and then seemed to come to some knowledge about TS generics closer to the substance – from the collection perspective. Based

Using Mock and Interface for Golang Unit Testing

In my work I often find that many engineers’ Golang unit tests are written in a problematic way, simply calling the code for output and including various IO operations, making it impossible to run the unit tests everywhere. Golang Unit Testing with Mock and Interface This article explains how to do unit tests properly in Golang. What is unit testing? Features of unit testing Unit testing is a very important part of quality assurance.

The relationship between iptables and the Linux kernel

Overview iptables is a basic firewall tool in Linux, and also a very common network workhorse, but iptables is really only an application layer, so how does iptables relate to the Linux kernel network stack, here I will give a brief introduction to this issue. NetFilter framework The Netfilter framework is a framework provided by the Linux kernel network for applications to register various Handlers, allowing users to control parts of the Linux network through the Netfilter framework.

New cgroups vulnerability in Linux kernel could elevate user privileges

A new cgroups vulnerability, codenamed CVE-2022-0492, which could be abused to evade containers in order to execute arbitrary commands on the container host. The vulnerability comes from a Linux kernel feature known as cgroups control group, cgroups allows processes to be organized into hierarchical groups so that CPU, memory, and other resource usage, disk I/O, and networking can be limited and monitored. However, because cgroups lacks internal validation of the release_agent file and fails to properly check whether the process setting the release_agent file has administrative privileges, an attacker can use this cgroups v1 release_agent feature to elevate privileges and accidentally bypass namespace isolation.

Deploying magento2 with docker-compose

Environment centos 7 2-core 8g docker 1.13.1 docker-compose 1.24.1 Versions of each container php:7.3-fpm-buster mysql:8.0 nginx:1.21 redis:6.2 frp using debian:10-slim as the base image build The specific version is 0.38.0 frp’s main role is to act as a proxy for xdebug elasticsearch:7.9 The magento version is 2.3.4 The following section assumes that docker and docker-compose are already installed. This is intended as a development environment, so the code is not

Understanding of JS prototype chains

Types in JS There are seven primitive types and Object in js undefined boolean number string bigint symbol null Primitive types number is a value in double-precision 64-bit binary format (-(253 -1) to 253 -1) based on the IEEE 754 standard. It does not give a specific type for integers. In addition to the ability to represent floating-point numbers, there are also signed values: +Infinity, -Infinity and NaN (Not-a-Number). bigint

Automatically archiving argo workflow logs using kubectl

The project uses argo-workflow as the workflow engine to orchestrate and run some hyperconverged cluster deployment related tasks, and the whole environment runs on a single node K3s. The main reason for choosing argo-workflow + K3s is to consume as few system resources as possible, since this environment will run on various laptops with different hardware configurations in the future 😂. After researching some common K8s deployment tools, we finally chose K3s, which consumes less system resources.

A simple comparison of QDir and std::filesystem

As a Qt developer, Qt provides me with a lot of useful infrastructure, such as the popular QString, QNetwork, etc. This is what the Qt platform provides me with, and I only need to develop on this platform. As a C++ developer, the C++ standard library is also the infrastructure I need to use, but the standard library provides less functionality than Qt, most notably the C++ std::string, which has

Prometheus Monitoring Kubernetes Job Resource False Alarm Issue

Someone mentioned a problem before, it is about Prometheus monitoring Job task false alarm problem, the general meaning of the CronJob control Job, the front of the execution failed, monitoring will trigger the alarm, after the solution to generate a new Job can be executed normally, but will still receive the alarm in front. This is because we generally keep some history when executing Job tasks to facilitate troubleshooting, so if there is a failed Job before, even if it will become successful later, the previous Job will continue to exist, and the default alarm rule used by most direct kube-prometheus installation and deployment is kube_job_ status_failed > 0, which is obviously inaccurate.

Introduction to EDNS Client Subnet Protocol

DNS systems use plaintext UDP protocol to communicate by default, so the content of users’ queries can be easily monitored, and the resolution results returned by servers can be easily tampered with. To solve this problem, technologies such as DNS over HTTPS/TLS/QUIC have been introduced in the hope of transmitting DNS queries in an encrypted manner. However, with the use of public DoH recursive resolution servers, authoritative DNS servers can only get the address of the recursive resolution server, but not the user’s address.

Run the Container using the init processs

Anyone who has followed Bare Metal related projects will have seen how the boot process, how to quickly provision a physical server, etc. is implemented, usually with a LiveOS running to achieve certain actions. The Tinkerbell project uses Linuxkit as the LiveOS, and the Plunder project uses BOOTy as the LiveOS. a few days ago @thebsdbox took out a part of BOOTy and showed the main implementation as ginit, so we can better understand the details of the installation.

Solve Gin Router Path Conflict

When using the gin framework, if there are two such routes. GET /users/:id GET /users/info gin will report an error: panic: 'info' in new path '/users/info' conflicts with existing wildcard ':id' in existing prefix '/users/:id' The reason is that the two routes have the same HTTP method (meaning GET/POST/PUT/DELETE, etc.) and request path prefix, and in the same route location, the first route is a wildcard (meaning :id of this form) parameter, and the second route is a normal string info, then a route conflict occurs.

Go doesn't need a Java-style GC

Modern languages like Go, Julia and Rust don’t need a garbage collector as complex as the one used by Java c#. But why is that? We first need to understand how garbage collectors work and how the various languages differ in the way they allocate memory. First, let’s look at why Java needs such a complex garbage collector. This article will cover many different garbage collector topics. Why Java relies

Several ways to solve the MySQL database ONLY_FULL_GROUP_BY exception

Using the employee example database as an example, the The test environment uses a single statement. SELECT * FROM employees GROUP BY gender; It works fine in the test environment, but it has problems online, reporting errors as follows. 1 2 3 4 5 6 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mse.msc_k8s_cluster.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by at sun.