var internStringsMap = make ( map [ string ] string ) func intern ( s string ) string { m := internStringsMap if v , ok := m [ s ]; ok { return v } m [ s ] = s return s } If you’ve interned all of your strings, meaning there’s only one canonical copy of each distinct string in memory, you can just compare the memory addresses (the pointers). package unique // Handle is a globally unique identity for some value of type T. type Handle [ T comparable ] struct { value * T } // Make returns a globally unique handle for a value of type T. Handles // are equal if and only if the values used to produce them are equal.