DEV Community

Jeff Lindsay
Jeff Lindsay

Posted on

4 1

A higher-level Go reflection package

Yesterday I did a quick, unscheduled stream to start a Go package that provides a simpler reflection API for Go values. Go has a reflect package that's pretty great, but doing basic things like calling a method or getting a property isn't as trivial as it could be. Plus the nature of reflection means this usually takes a lot of experimentation to get right. At least for me, and I've worked with Go reflection quite a bit.

The idea was to provide an API that looks more like the syscall/js API, which is used for interacting with JavaScript values of WebAssembly hosts. Besides being simpler, this API has methods for getting and setting properties and calling methods. These are some of the most common operations in reflection, but using reflect by itself doesn't just give you these.

So that's all this is. A simple higher level wrapper for the reflect package. This can be used for more easily making JavaScript proxy objects to Go values in WebAssembly or exposing values over RPC, both of which I expect to be doing. But also, I use reflection a lot and this will save a lot of time remembering how to do some of these basic operations.

Anyway, I got the simple version of the interesting methods done, as well as some basic tests. I might work on this more off stream or as needed in projects that use this.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more