Unicode and UTF-8 in Golang

As we know, inside the computer, in order to convert binary data to the display, it is necessary to encode, that is, the displayable characters correspond to the binary data one by one, such as ASCII code, which is a Byte of data to represent the English characters plus some English symbols. As for Chinese, we obviously can not use just one Byte to represent, we need to use a larger space.

Golang in Docker

Golang as a static language must be compiled before running, while dynamic languages like Python can be run directly in an interpreter environment, so their best practices for docker deployment will be slightly different. Dockerfile for Golang Here I’ll start by giving the Dockerfile for Goalng directly. 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 35 36 37 38 39 40 41 42 43 FROM golang:alpine AS builder # Set necessary environmet variables needed for our image ENV GO111MODULE=on \ GOPROXY=https://goproxy.

Embrace Atomic CSS-in-JS

Nowadays, Atomic CSS is gaining more and more attention. Compared to the traditional CSS writing method where each component has one CSS class. With Atomic CSS, each CSS class uniquely corresponds to a separate CSS rule. As the number of components grows, more and more CSS rules can be reused. The final CSS product is much smaller, allowing for a quantum leap in page load speed. History of CSS authoring

Scanner and Valuer interfaces in the Golang database module

The Scanner / Valuer interface provides the ability to convert custom types and database types to each other. Problems encountered in reality When developing applications, some of the fields in the tables are customized, for example. 1 2 type Day time.Time // Time in days type LocaleTime time.Time // Time of local formatting Why do I need to redefine these types? My reason here is to output normalized values when providing the JSON interface downstream.

Managing Tekton components with Tektoncd Operator

Tektoncd Operator is a Kubernetes extension for installing, upgrading and managing TektonCD Pipelines, Dashboard, Triggers, etc. on a Kubernetes cluster. We just need to write the yaml for each component to manage Tekton components directly. CRD Description TektonConfig Configure the Tekton components to be installed and managed. TektonPipeline Configure the installation to manage Tekton Pipeline components. TektonTrigger Configure the installation to manage the Tekton Trigger component. TektonDashboard Configure the installation to manage Tekton Dashboard components.

Cloud Native Declarative Database Structure Migration Tool - SchemaHero

SchemaHero is an open source declarative database schema migration cloud-native tool that converts schema definitions into migration scripts that can be applied in any environment. Written as a CLI tool and Kubernetes Operator, SchemaHero eliminates the task of creating and managing sequential migration scripts that are compatible with all environments in which applications are running. Many database schema management tools create an imperative interface that requires the developer to know the current state of the schema and the relevant commands to migrate the current schema (and associated data) to the new schema.

FAQ about Go plugin and solutions

I have encountered a lot of problems in designing and implementing extension development products based on the Go native plug-in mechanism, and since there is very little relevant information in this area, I would like to take this opportunity to make a very rough summary, and hope that it will help you. This article only say the problem and the solution, do not read the code. Some background knowledge 2.1 Runtime In general, in the field of computer programming languages, the concept of “runtime” is associated with languages that require the use of a vm.

Implementing bidirectional data exchange between kernel and user states of eBPF programs using Golang

In the previous two articles, both “Developing eBPF programs in C” and “Developing eBPF programs in Go” are hello world level, which may be useful, but not very practical. Generally speaking, a practical eBPF program has data exchange between its kernel state part and user state part, and with this data exchange, eBPF can play a more powerful role. And to make an eBPF program more practical, eBPF MAP is the mechanism that cannot be bypassed.

Get OS information using gopsutil

What do you do if you need to get the usage of your host’s hard disk, CPU, memory, processes, etc. in Golang? A simple idea would be to run some commands like ps, cd, top through os/exec and then parse the results of those commands. Of course, based on the Linux idea that everything is a file, a more straightforward approach would be to read the contents of the relevant files, such as those in the /proc directory.

PostgreSQL 15 improvements to UNIQUE and NULL

Summarize this improvement in the following sentence. Support for unique constraints and indexing treats null values as identical. Previously, null values were indexed as distinct values. Now you can create constraints that treat null values as identical by using unique nulls not distinct. Two unique styles Create the example table. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 CREATE TABLE null_old_style ( id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, val1 TEXT NOT NULL, val2 TEXT NULL, CONSTRAINT uq_val1_val2 UNIQUE (val1, val2) ); CREATE TABLE null_new_style ( id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, val1 TEXT NOT NULL, val2 TEXT NULL, CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2) ); Changes in supported data In postgresql 14 or earlier, the uniqueness constraint treats null as not the same as null.

Exposing Go program runtime metrics with expvar

Obtaining the application’s operational metrics gives us a better understanding of its actual status. By connecting these metrics to monitoring systems such as prometheus, zabbix, etc., the application can be continuously checked and any abnormalities can be alerted and handled in a timely manner. Pull and Push There are two ways to interface with monitoring systems, one is Pull and the other is Push. In the case of Prometheus, for example, the application exposes an HTTP interface for Prometheus to periodically grab metrics through, which is called Pull, while Push is when the application actively pushes metrics to PushGateway.

serde custom serialization

serde is pretty much the most commonly used serialization and deserialization library in the Rust ecosystem today. Golang Implementation As a Golang programmer, it’s important to compare. The official Golang library directly implements serialization and deserialization of json. For both serialization and deserialization, Go uses a simple interface called interface. 1 2 3 4 5 6 7 8 9 // https://pkg.go.dev/encoding/json#Marshaler type Marshaler interface { MarshalJSON() ([]byte, error) } // https://pkg.

VXLAN Protocol for Cloud-Native Virtual Networks

The first time I got to know VXLAN was when I looked at a network plugin called flannel used in k8s that has a VXLAN mode, which implements an Overlay Network that connects all containers together. So in this article, let’s take a look at how VXLAN connects the networks between different containers. Overview Before we look at VXLAN, let’s take a look at its predecessor, VLAN, whose full name is Virtual Local Area Network, a layer 2 (data link layer) network used to partition broadcast domains.

Golang Event Bus

Recently in learning the code of the open source project Grafana, I found that the author has implemented an event bus mechanism, which is used in a large number of projects, the effect is also very good, the code is also relatively simple. https://github.com/grafana/grafana/blob/main/pkg/bus/bus.go 1. Registration and invocation This writeup is seen everywhere inside this project. 1 2 3 4 5 6 7 8 9 10 11 12 13 14

RPC-based plug-in mechanism in Golang

Recently there is a need to implement the plug-in mechanism inside the project, the so-called plug-in means that the program can be extended without releasing a new version of the case, this plug-in mechanism is particularly widely used, common such as our browser extensions, Nginx extensions, PHP extensions and so on. Inside the Go language, it comes with an official plugin extension mechanism, which I have described in a previous

How Kubernetes achieves high availability of components

In Kubernetes, components such as Controller Manager, Scheduler, and user-implemented Controllers are highly available by means of multiple replicas. However, multiple replica Controllers working at the same time inevitably trigger a contention condition for the resources they are listening to, so usually only one replica is working between multiple replicas. In order to avoid this competition, Kubernetes provides a Leader election model, where multiple replicas compete with each other for the Leader, and only the Leader will work, otherwise it will wait.

Golang Object-Oriented Interface Programming

When it comes to object-oriented (OOP), many people have heard of encapsulation, inheritance, polymorphism, these characteristics, in essence, object-oriented is just a software programming ideas. But from this comes the concept of object-oriented language, of which Java is the most typical representative, is a fully object-oriented language, expressed in the language level there are class and object design. After all, the main goal of any software engineering is to achieve

Plug-in programming with Go Plugin

Speaking of plug-ins, many people are not unfamiliar with this thing, in general, plug-in has several benefits, one is to increase the program scalability, rich functionality. In addition, you can also achieve hot updates, some large applications, often several GB of installation procedures, if a small update will need to re-download the entire program, at this time we can update the module plug-in often, so that when the update only need to download a small update file.

kubelet Remote Debugging

1. kubelet startup command analysis kubelet is a systemd service. Take the v1.23.4 k8s cluster installed with Kubeadm tool as an example, the path of the configuration file of this service is /etc/systemd/system/kubelet.service.d/10-kubeadm.conf. The contents are as follows. 1 2 3 4 5 6 7 8 9 10 11 # Note: This dropin only works with kubeadm and kubelet v1.11+ [Service] Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf" Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml" # This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.

In-depth understanding of the principle of nocopy in Golang

01 How to set the object not to be copied sync.Pool cannot be copied. 1 2 3 4 5 6 7 8 9 10 11 // sync/pool.go type Pool struct { noCopy noCopy ... } type noCopy struct{} func (*noCopy) Lock() {} func (*noCopy) Unlock() {} sync.Mutex cannot be copied. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // sync/mutex.