Urgent.News

What's breaking now, across thousands of outlets.

Tech

Method Sets, Embedding, and Interface Satisfaction in Go: The Hidden Contract Behind API Boundaries

The Problem Is Never Just "It Doesn't Implement the Interface" Go's interface satisfaction is structural and compile-time, which sounds safe until you're debugging why a concrete type that clearly has all the right methods refuses to satisfy an interface in a different package—or worse, satisfies it silently and then behaves incorrectly at runtime because pointer receivers were embedded into a…

Go's interface satisfaction rules can be complex, leading to subtle bugs in large systems. When a concrete type embeds another by value instead of pointer, it only inherits the methods of the embedded type, not the promoted methods from the embedded pointer type. This asymmetry often goes unnoticed until the code reaches a package boundary.

In services with multiple layers and SDKs, the consequence is that a type might satisfy an interface locally but fail to do so when passed around. This is particularly problematic when embedding a struct by value, as it hides the promotion of methods from embedded pointer types. The compiler can catch direct assignments but not the deceptive pattern of silent satisfaction, which can only be revealed through trial and error or testing.

Developers frequently embed by value by habit, only learning the importance of embedding by pointer when they encounter the compile error later. This misunderstanding can lead to silent failures at runtime, especially in scenarios like API integrations where the same type might be used across different packages with varying requirements.

The issue is a fundamental part of Go's contract and can be a hidden source of bugs that are hard to trace.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

A scheduled job can be healthy while its work is overdue

Disclosure: This article was written by an AI coding agent from this project's source code, execution records, and macOS power logs.

  • Healthy job may have overdue work, as shown by AI news pipeline
  • Dashboard incorrectly confirmed job existence despite overdue work
  • Revised lock acquisition ensures due tasks with unfinished work are visible

Our watchdog restarted a healthy agent 24 times a day for months, and its own log said everything was fine

Disclosure first: I work on macyou.co, which rents Apple Silicon machines, so I have a stake in where people run things. Everything below is from our own install and from a harness anyone can run…

  • Watchdog restarted healthy agent 24 times daily for months
  • Health check mechanism incorrectly identified hung processes
  • Suggested solution: agent writes heartbeat file to indicate success

More from Thursday 24 September →