Files
Dalton Hubble dbe684869d Rename util package to internal to prevent library use
* It's conventional to implement Terraform providers within an
internal package, since they're not intended to be consumed or
relied upon as Go libraries
2024-06-22 10:11:28 -07:00

27 lines
634 B
Go

package internal
import (
"hash/crc32"
"strconv"
)
// Migrated from the V1 SDK github.com/hashicorp/terraform-plugin-sdk/helper/hashcode
// https://www.terraform.io/plugin/sdkv2/guides/v2-upgrade-guide#removal-of-helper-hashcode-package
// Hashcode hashes a string to a unique hashcode.
//
// crc32 returns a uint32, but for our use we need
// and non negative integer. Here we cast to an integer
// and invert it if the result is negative.
func Hashcode(s string) string {
v := int(crc32.ChecksumIEEE([]byte(s)))
if v >= 0 {
return strconv.Itoa(v)
}
if -v >= 0 {
return strconv.Itoa(-v)
}
// v == MinInt
return "0"
}