Interface Conversion — Type Does Not Implement Interface

cannot use x (variable of type *MyStruct) as type MyInterface: *MyStruct does not implement MyInterface (missing Method method)

Quick Answer

Your type does not implement all the methods required by the interface. Add the missing method with the correct signature.

Why This Happens

In Go, interfaces are satisfied implicitly. If a type is missing even one method, or if the method signature does not match exactly (wrong receiver type, different parameters), the type does not satisfy the interface. A common mistake is defining methods on the value type but trying to use a pointer, or vice versa.

The Problem

type Writer interface {
    Write(data []byte) error
}

type MyWriter struct{}

func (w MyWriter) Write(data string) error { // wrong parameter type
    return nil
}

var w Writer = &MyWriter{} // does not implement Writer

The Fix

type MyWriter struct{}

func (w *MyWriter) Write(data []byte) error {
    return nil
}

var w Writer = &MyWriter{} // now implements Writer

Step-by-Step Fix

  1. 1

    Identify the missing method

    The compiler error tells you exactly which method is missing or has the wrong signature.

  2. 2

    Compare the signatures

    Check the interface definition and your method signature side by side. Look for differences in parameter types, return types, and receiver type.

  3. 3

    Fix the method

    Update your method to match the exact signature required by the interface.

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