サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
衆院選
eli.thegreenplace.net
An exciting proposal is expected to land in Go 1.22 - enhancing the pattern-matching capabilities of the default HTTP serving multiplexer in the net/http package. The existing multiplexer (http.ServeMux) offers rudimentary path matching, but not much beyond that. This led to a cottage industry of 3rd party libraries to implement more powerful capabilities. I've explored these options in my REST Se
I put together a simple static file server in Go - useful for local testing of web applications. Check it out at https://github.com/eliben/static-server If you have Go installed on your machine, you don't have to download anything else; you can run: And it will start serving the current directory! Run it with -help for usage information. No configuration files needed - the default is useful and yo
This post is best described as a technology demonstration; it melds together web servers, plugins, WebAssembly, Go, Rust and ABIs. Here's what it shows: How to load WASM code with WASI in a Go environment and hook it up to a web server. How to implement web server plugins in any language that can be compiled to WASM. How to translate Go programs into WASM that uses WASI. How to translate Rust prog
This post shows how to set up SSH port forwarding ("tunnels") - both local and remote - using the extended Go standard library. Setup While you could set up localhost forwarding for testing, to discuss a more realistic scenario I would recommend spinning up a basic VPS. For the purpose of writing this post, I run a bare-bones Ubuntu VPS on Digital Ocean with the public IP address 159.89.238.232 (a
It's been a while since I've last rewritten my favorite lexical analyzer :-) That post is the last in a series implementing a lexer for the TableGen language in a variety of programming languages, using multiple techniques. The last lexer written, in Go, was very fast indeed - processing 1 MiB of source in about 20 milliseconds. The other day I started wondering whether Go compiler improvements fr
Recently, a new set of sorting functions has landed in Go's golang.org/x/exp/slices package [1]. These functions leverage Go generics to provide a more ergonomic API for sorting (without requiring users to implement sort.Interface), and also deliver a nice performance improvement, as the CL demonstrates. In this post, I'll dive deep into why these generic functions are faster than the existing one
Coding interviews have never been popular in the programming community; I mean, they are prevalent, since many companies still use them to filter candidates, but they are vastly unpopular in the community because people find them too hard, too unfair, too unrepresentative of reality and so on. There are viral stories all around - like when the creator of Homebrew failed Google's interviews [1]. In
Traits are a central feature of Rust, critical for its implementation of polymorphism; traits are used for both static (by serving as bounds for generic parameters) and dynamic (by having trait objects to serve as interfaces) polymorphism. This post assumes some familiarity with traits and discusses only a specific aspect of them - how extension traits affect code readability. To learn the basics
To implement its safety guarantees, the Rust compiler keeps careful track of ownership and references throughout a program. This makes writing certain kinds of data structures challenging; in particular, data structures that have circular references. Let's start with a simple binary tree: struct Tree { root: Option<Node>, } struct Node { data: i32, left: Option<Box<Node>>, right: Option<Box<Node>>
This post is a basic introduction to running HTTPS servers and clients in Go using TLS. It assumes some familiarity with public-key crypto. Feel free to check out my earlier posts about RSA and the Diffie-Hellman Key Exchange; TLS uses the elliptic-curve version of Diffie-Hellman. I won't be covering how the protocol itself works in detail here, but if you're interested I recommend to read up on t
When I wrote the introductory article for libjit, I aimed it at programmers who know what JITs are, at least to some extent. I did mention what a JIT is, but only very briefly. The purpose of this article is to provide a better introductory overview of JITing, with code samples that don't rely on any libraries. Defining JIT JIT is simply an acronym for "Just In Time". That, in itself, doesn't help
This is the first post in a series about writing REST servers in Go. My plan with this series is to implement a simple REST server using several different approaches, which should make it easy to compare and contrast these approaches and their relative merits. Here is a list of posts in the series: Part 1 - standard library (this post) Part 2 - using a router package Part 3 - using a web framework
Programmers that come to Go from Python often wonder "do I need something like virtualenv here?" The short answer is NO; this post will provide some additional details. While virtualenv in Python is useful in many situations, I think it'd be fair to divide them into two broad scenarios: for execution and for development. Let's see what Go offers for each of these scenarios. Execution There are mul
This is the first post in a series about JIT compilers. The plan is to take a simple input language and develop some interpreters and JITs for it, in roughtly increasing degree of complexity. It's my hope that by the end of the series readers will have a good understanding of what it takes to develop a JIT compiler and what are some of the tools available to assist with the task. The input languag
This is the first post in a multi-part series describing the Raft distributed consensus algorithm and its complete implementation in Go. Here is a complete list: Part 0: Introduction (this post) Part 1: Elections Part 2: Commands and log replication Part 3: Persistence and optimizations Raft is a relatively new algorithm (2014), but it's already being used quite a bit in industry. The best known e
This post is going to discuss how to gracefully shut down a TCP server in Go. While servers typically never stop running (until the process is killed), in some scenarios - e.g. in tests - it's useful to shut them down in an orderly way. High-level structure of TCP servers in Go Let's start with a quick review of the high-level structure of TCP servers implemented in Go. Go provides some convenient
Update (2023-09-19): We've now published similar guidelines as part of Go's official documentation. This blog post will remain up-to-date. A very common question Go beginners have is "how do I organize my code?". Some of the things folks are wondering about are: How does my repository structure reflect the way users import my code? How do I distribute commands (command-line programs that users can
Update (2023-09-20): Go fixes the loop variable capture gotcha in the 1.22 release. While the technical details of this article remain true, all the examples will produce the "expected" output. The Go wiki has a page titled CommonMistakes. Amusingly, it only lists a single entry at this time - using goroutines on loop iterator variables, providing this example:
RSA has been a staple of public key cryptography for over 40 years, and is still being used today for some tasks in the newest TLS 1.3 standard. This post describes the theory behind RSA - the math that makes it work, as well as some practical considerations; it also presents a complete implementation of RSA key generation, encryption and decryption in Go. The RSA algorithm The beauty of the RSA a
Updated (2023-05-08): the Go compiler keeps evolving and it takes time to keep up with changes. While the general gist of this post remains true and it's worth reading to understand how the compiler works on a high level, the details of the modifications are slightly different now. To see up-do-date changes that work with the latest Go (in-development version 1.21 at the time of this update), chec
I've been enjoying using Go's database/sql package for working with databases. Recently, some mentions of gorm piqued my curiosity about using ORMs in Go vs. using database/sql directly. Having had some mixed experiences with ORMs in the past, I decided to start with a practical experiment by writing the same simple application with and without gorm, and comparing the results in terms of effort sp
Recently I've gotten into answering Go questions on StackOverflow, and one of the patterns I noticed are many repetitive questions about JSON processing. The goal of this post is to collect a "cookbook" of JSON processing code and examples; think of it as a vastly expanded version of the JSON gobyexample page. It's a living document - I will update it once in a while when I find new patterns/probl
Go's built-in net/http package is convenient, solid and performant, making it easy to write production-grade web servers. To be performant, net/http automatically employs concurrency; while this is great for high loads, it can also lead to some gotchas. In this post I want to explore this topic a bit. Ensuring safe concurrent access from handlers to data Let's start with a very simple example of a
In this post I want to explore the costs of threads on modern Linux machines, both in terms of time and space. The background context is designing high-load concurrent servers, where using threads is one of the common schemes. Important disclaimer: it's not my goal here to provide an opinion in the threads vs. event-driven models debate. Ultimately, both are tools that work well in some scenarios
This article's aim is to explain how a modern operating system makes it possible to use shared libraries with load-time relocation. It focuses on the Linux OS running on 32-bit x86, but the general principles apply to other OSes and CPUs as well. Note that shared libraries have many names - shared libraries, shared objects, dynamic shared objects (DSOs), dynamically linked libraries (DLLs - if you
Go has a unique approach to error handling, with a combination of explicit error values and an exception-like panic mechanism. In this post I'm looking at the philosophical aspects of panic, trying to understand some of the conflicting guidelines coming from the Go team. Most of all, it's a story of pragmatism in language design, with some musings on the merits and dangers of a pragmatic approach.
The futex (short for "Fast userspace mutex") mechanism was proposed by Linux contributors from IBM in 2002 [1]; it was integrated into the kernel in late 2003. The main idea is to enable a more efficient way for userspace code to synchronize multiple threads, with minimal kernel involvement. In this post I want to provide a basic overview of futexes, how they work, and how they're used to implemen
In this brief post I want to discuss a fairly unusual feature of Haskell - functions that can be parameterized by their return type. Parametric vs. ad-hoc polymophism It's worth beginning with a quick discussion of the two most common kinds of compile-time polymorphism present in Haskell: parametric polymophism and ad-hoc polymorphism. Parametric polymorphism is possible when we can define a certa
Recently, while idly browsing through the source code of Python, I came upon an interesting comment in the bytecode VM implementation (Python/ceval.c) about using the computed gotos extension of GCC [1]. Driven by curiosity, I decided to code a simple example to evaluate the difference between using a computed goto and a traditional switch statement for a simple VM. This post is a summary of my fi
次のページ
このページを最初にブックマークしてみませんか?
『Eli Bendersky's website』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く