Skip to content

Instantly share code, notes, and snippets.

@Yapcheekian
Last active August 9, 2023 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yapcheekian/467c4eb610bedf57f071ebfa17f3515a to your computer and use it in GitHub Desktop.
Save Yapcheekian/467c4eb610bedf57f071ebfa17f3515a to your computer and use it in GitHub Desktop.
generic.md
type Model interface {
	comparable
	TableName() (schema, table string)
}

type Change[T Model] struct {
	New T
	Old T
}

type ModelHandlerFunc[T Model] func(change T) error
type ModelHandlers[T Model] map[T]ModelHandlerFunc[T]

func Consume[T Model](mh ModelHandlers[T]) error {
	return nil
}

type Comment struct {
	ID string
}

func (c *Comment) TableName() (string, string) {
	return "public", "comments"
}

func main() {
	c := Comment{}

	Consume(map[*Comment]ModelHandlerFunc[*Comment]{
		&c: func(change *Comment) error {
			return nil
		},
	})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment