Simple and easy to use short url server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

20 lines
401 B

package terse
import (
"bytes"
"hash/crc32"
)
const ALPHABET string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~"
const BASE uint32 = uint32(len(ALPHABET))
func GetShortCode(url []byte) string {
var code bytes.Buffer
num := crc32.ChecksumIEEE(url)
for num > 0 {
next := (num % BASE)
code.WriteRune(rune(ALPHABET[next]))
num = num / 62
}
return code.String()
}