Skip to content

Instantly share code, notes, and snippets.

@devig
Created April 3, 2023 05:32
Show Gist options
  • Save devig/9f1d5f37f305c870d37ba3313b48741d to your computer and use it in GitHub Desktop.
Save devig/9f1d5f37f305c870d37ba3313b48741d to your computer and use it in GitHub Desktop.
Check if struct implemented interface
package main
import (
"fmt"
)
type Foo interface {
bar(name string)
}
type Bar struct{}
func (*Bar) bar(id string) {}
type Baz struct{}
func (*Baz) bar(id int) {}
var _ Foo = new(Bar)
//var _ Foo = new(Baz) //error
func main() {
fmt.Println("Hello, check")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment