Skip to content

Instantly share code, notes, and snippets.

@olehcambel
Last active May 5, 2020 10:24
Show Gist options
  • Save olehcambel/60fedac88a251f88bfcc0f9aae35a8b9 to your computer and use it in GitHub Desktop.
Save olehcambel/60fedac88a251f88bfcc0f9aae35a8b9 to your computer and use it in GitHub Desktop.
A way to check if struct implements an interface
package main
import (
"sort"
)
type RawMessage []int
func (mes RawMessage) Len() int {
return len(mes)
}
var _ sort.Interface = (*RawMessage)(nil)
/*
^^^^^^^
cannot use (*RawMessage)(nil) (type *RawMessage) as type sort.Interface in assignment:
*RawMessage does not implement sort.Interface (missing Less method)
*/
func main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment