Cannot Embed Unexported Interface

cannot embed unexported type somePackage.myInterface

Quick Answer

You are trying to embed an unexported interface from another package. The interface must be exported (start with uppercase) to be embedded externally.

Why This Happens

In Go, you can only embed exported types from other packages. If the interface or struct type starts with a lowercase letter, it is unexported and cannot be embedded from outside its package.

The Problem

// package auth
type validator interface {
    Validate() error
}

// package main
type MyAuth struct {
    auth.validator // cannot embed unexported type
}

The Fix

// package auth
type Validator interface {
    Validate() error
}

// package main
type MyAuth struct {
    auth.Validator
}

Step-by-Step Fix

  1. 1

    Identify the unexported type

    Check if the embedded type starts with a lowercase letter.

  2. 2

    Export the type

    Capitalize the first letter of the type name in the defining package.

  3. 3

    Update all references

    Update all references to the type to use the new capitalized name.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free