Traefik Architecture and Source Code Analysis: A Deep Dive

Traefik is a widely adopted open-source HTTP reverse proxy and load balancer that simplifies the routing and load balancing of requests for modern web applications. It boasts dynamic configuration capabilities and supports a multitude of providers, positioning itself as a versatile solution for orchestrating complex deployment scenarios. In this blog post, we will delve into the architecture of Traefik and dissect the key components of its source code to furnish a more nuanced understanding of its operational mechanics. ...

March 9, 2024 · zhoukuncheng

Streamlining Real-Time Data: Master HTML5 SSE like ChatGPT

Introduction In the age of real-time interactivity where services like ChatGPT excel, it’s crucial for developers to leverage technologies that allow for seamless data streaming in their applications. This article will delve into the world of HTML5 Server-Sent Events (SSE), a powerful tool akin to the technology behind conversational AI interfaces. Similar to how ChatGPT streams data to provide instant responses, SSE enables web browsers to receive updates from a server without the need for repetitive client-side requests. Whether you’re building a chat application, a live notification system, or any service requiring real-time data flow, this guide will equip you with the knowledge to implement SSE efficiently in your applications, ensuring a responsive and engaging user experience. ...

December 30, 2023 · zhoukuncheng

Structured Concurrency

Introduction Definition According to Wikipedia: Structured concurrency is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by using a structured approach to concurrent programming. The core concept is the encapsulation of concurrent threads of execution (here encompassing kernel and userland threads and processes) by way of control flow constructs that have clear entry and exit points and that ensure all spawned threads have completed before exit. Such encapsulation allows errors in concurrent threads to be propagated to the control structure’s parent scope and managed by the native error handling mechanisms of each particular computer language. It allows control flow to remain readily evident by the structure of the source code despite the presence of concurrency. To be effective, this model must be applied consistently throughout all levels of the program – otherwise concurrent threads may leak out, become orphaned, or fail to have runtime errors correctly propagated. ...

August 1, 2022 · zhoukuncheng

Introduction to Go 1.18 Generics

What are Generics? Generic programming is a style or paradigm of computer programming. Generics allow programmers to write code using types that are specified later, which are then instantiated when the code is used. Basic Usage of Generics in Golang Examples Map Operation package main import ( "fmt" ) func mapFunc[T any, M any](a []T, f func(T) M) []M { n := make([]M, len(a), cap(a)) for i, e := range a { n[i] = f(e) } return n } func main() { vi := []int{1, 2, 3, 4, 5, 6} vs := mapFunc(vi, func(v int) string { return "<" + fmt.Sprint(v * v) + ">" }) fmt.Println(vs) } Min Max Functions ...

March 16, 2022 · zhoukuncheng

Developing RESTful APIs with gRPC-Gateway

Introduction to gRPC-Gateway gRPC-Gateway is a plugin for protoc. It works by reading a gRPC service definition and generating a reverse proxy server that translates a RESTful JSON API into gRPC. This server is generated according to the custom options in your gRPC definition. Installation and Usage Dependencies Tool Introduction Installation protobuf Command line tool for protocol buffer compilation http://google.github.io/proto-lens/installing-protoc.html protoc-gen-go Generates .go files from proto files https://grpc.io/docs/languages/go/quickstart/ protoc-gen-go-grpc Generates gRPC related .go files from proto files https://grpc.io/docs/languages/go/quickstart/ protoc-gen-grpc-gateway Generates gRPC-gateway related .go files from proto files https://github.com/grpc-ecosystem/grpc-gateway#installation protoc-gen-openapiv2 Generates parameter files required for Swagger documentation from proto files https://github.com/grpc-ecosystem/grpc-gateway#installation buf Protobuf management tool, optional, simplifies command line operations and protobuf file management https://docs.buf.build/installation Steps Write buf configuration buf.gen.yaml ...

March 13, 2022 · zhoukuncheng

Concurrency Pattern Differences between Python and Go

Concurrency in Python In Python, early concurrency methods were dominated by traditional multi-processing and multi-threading, similar to Java. At the same time, there were many third-party asynchronous solutions (gevent/tornado/twisted, etc.). In the Python 3 era, the official asyncio library and async/await syntax were introduced as Python’s official coroutine implementation, which gradually became popular. Processes Example of multi-processing programming: from multiprocessing import Process def f(name): print('hello', name) if __name__ == '__main__': p = Process(target=f, args=('bob',)) p.start() p.join() The API of multiprocessing is close to threading, making it relatively easy to create multi-process programs. It is a solution recommended by Python officially to bypass the GIL restriction of multi-threading. However, it should be noted that the parameters for creating a process need to be pickle-serializable. It is best to use process-safe data structures like Pipe and Queue (Official Programming guidelines). ...

August 30, 2021 · zhoukuncheng