Skip to content

Instantly share code, notes, and snippets.

@StevenACoffman
Created May 18, 2025 00:47
Show Gist options
  • Save StevenACoffman/5147df242b08756a8ee9691d19eea189 to your computer and use it in GitHub Desktop.
Save StevenACoffman/5147df242b08756a8ee9691d19eea189 to your computer and use it in GitHub Desktop.
Go Diff Tricks
// ProtoDiff generates an indented summary of the diff between two protos'
// YAML representations. See ProtoToYAML for documentation on rewrites.
func ProtoDiff(a, b protoutil.Message, args DiffArgs, rewrites func(interface{})) string {
	toYAML := func(m protoutil.Message) string {
		if m == nil {
			return ""
		}
		str, err := ProtoToYAML(m, false /* emitDefaults */, rewrites)
		if err != nil {
			panic(err)
		}
		return strings.TrimSpace(str)
	}

	return Diff(toYAML(a), toYAML(b), args)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment