In VSCode, how do I generate the implementation for an interface?
Say, I have this interface:
type ServerInterface interface {
    // Set value for a device
    SetSomethingForDeviceById(ctx echo.Context, id int64) error
}
How do I generate methods that implement it?
VScode supports interface generation with the Go extension.
Here's how you do it:
First, you start with defining your struct:
type ApiServer struct {}
Now, use Ctrl-Shift-P, and find this command: "Go generate interface stubs"

Now type something like this: receiver name, type, interface name:
s ReceiverType package.InterfaceName

Hit Enter. Missing methods are generated:
package api
import "github.com/labstack/echo/v4"
// Set value for a device
func (s ApiServer) SetSomethingForDeviceById(ctx echo.Context, id int64) error {
    panic("not implemented")
}
@clément-jean added that:
this command depends on https://github.com/josharian/impl: you need to install it before being able to generate the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With