Created
April 3, 2023 05:32
-
-
Save devig/9f1d5f37f305c870d37ba3313b48741d to your computer and use it in GitHub Desktop.
Check if struct implemented interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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