func normalize(col *collate.Collator, buf *collate.Buffer, in []byte) ([]byte, error) { // We cannot pass invalid UTF-8 to the collator. if !utf8.Valid(in) { return nil, fmt.Errorf("cannot normalize string containing invalid UTF-8: %q", string(in)) } // Ref: http://dev.mysql.com/doc/refman/5.6/en/char.html. // Trailing spaces are ignored by MySQL. in = bytes.TrimRight(in, " ") // We use the collation key which can be used to // perform lexical comparisons. return col.Key(buf, in), nil }