Go protobuf upgrade — github.com/golang/protobuf to google.golang.org/protobuf

记一次奇妙的go-protobuf包升级之旅

A recent protobuf dependency bump looked routine—until CI and protoc disagreed.

Dependabot suggested moving github.com/golang/protobuf from v1.3.5 to v1.4.0.

Read More

OPA bundles — package policy and data for distributed OPA servers

OPA进阶-分布式利器Bundle

A bundle is how OPA ships policy and data as one artifact. The engine was built for sidecars and daemons in cloud-native setups, so distribution, updates, and observability show up early — not as an afterthought.

Bundles cover:

  • Central config for policy + data
  • Hot(ish) policy refresh without redeploying every consumer
  • Health, metrics, and decision logs from many OPA instances

With Rego on top, that’s what makes OPA feel like a general policy layer instead of a one-off authz library.

Below: bundle layout, server APIs, remote bundle config, embedding options, and metrics. There’s a docker-compose demo in the koans repo—run it locally once you’ve skimmed the sections.

Read More

OPA Rego comprehensions — object, array, and set

OPA进阶-简洁的推导式

Comprehensions build composite values from inner queries — object, array, or set — in one expression. The official definition is dry; examples stick better.

We’ll aggregate a list of file paths in different ways.

Read More

OPA Rego — functions vs virtual documents and when to use each

OPA进阶-函数与虚拟文档要分清

Rego gives you two ways to package logic: functions and virtual documents. They overlap on paper; in practice the choice comes down to whether you need a relation you can iterate.

We’ll use a file list in input and ask: which paths look like config files?

Read More

OPA local development — CLI (run, eval, test) and vscode-opa

如何优雅的使用opa进行开发

After the RBAC intro, you’ll want opa on your PATH, a handful of CLI commands (run, eval, test, …), and the VS Code extension so you’re not retyping flags.

Read More

Open Policy Agent intro — write your first RBAC rule in Rego

OPA-重新定义规则引擎-入门篇

OPA (Open Policy Agent) is a policy engine written in Go. Its Rego language is declarative, general-purpose, and unpleasantly good at expressing rules you used to spell out in application code.

In April 2019 OPA joined the CNCF as an incubating project (announcement). English-language material was thinner then than it is now; I kept running into OPA at work and wrote this series to pay that forward.

If you’re picking a policy engine, OPA belongs on the short list.

What is OPA?

The official framing is in the OPA philosophy docs. The bullets that stuck with me:

  • Lightweight, general-purpose policy evaluation
  • Can live alongside your services
  • Deploy as a sidecar, a host daemon, or an embedded library

opa

Read More

Go interface devirtualization — when the compiler skips convT64

Dig101-Go之interface调用的一个优化点

Dig101: dig more, simplify more, know more.

This follows the Dig101 piece on Go interface layout.

For interface Stringer and concrete type Binary, why does conversion call convT64 while devirt does not?

Read More

Dig101 — how Go implements interface values (eface, iface, itab)

Dig101-Go之读懂interface的底层设计

Dig101: dig more, simplify more, know more

Runtime layout behind Go’s interface values — what “everything is an interface” looks like in memory.

An interface is a set of method signatures. It gives you contracts, abstractions, and constraints on implementations.

Values with no methods are the empty interface interface{}; in that sense every concrete value can live in an interface slot. (Before generics, interfaces were the usual stand-in for parametric code.)

Russ Cox on why interfaces matter:

From a language-design perspective, Go’s interfaces are static, checked at compile time, and dynamic when needed. If I could export one Go feature to other languages, it would be interfaces.
Go Data Structures: Interfaces

How is that represented in memory? How does duck typing work? What happens on a type assertion? Those are the questions below.

Read More

GDB for Go on Docker and macOS — ptrace, codesign, and build flags

Tips-如何优雅的使用GDB调试Go

Tips: all for hands-free.

This series is a log of small tricks that save time day to day.

One goal: don’t let repetitive chores numb you — automate when you can.


Today: using GDB on Go without fighting the setup.

Why GDB?

If you care what the code is really doing, it’s hard to beat — especially when you’re chasing a bug.

For deep dives, see Using a debugger to learn Go (Xargin).

Getting from install to “it works” can be painful (Mac especially). This post is about staying out of that rabbit hole.

(Docker and macOS both covered.)

Read More