reduce default short values
This commit is contained in:
parent
34853c0dbd
commit
e0e1a775bc
|
@ -15,11 +15,11 @@ import (
|
|||
|
||||
const (
|
||||
// DefaultShortLength is the default length of the short URL.
|
||||
DefaultShortLength = 8
|
||||
DefaultShortLength = 5
|
||||
// MinShortLength is the minimum length of the short URL.
|
||||
MinShortLength = 4
|
||||
// MaxShortLength is the maximum length of the short URL.
|
||||
MaxShortLength = 32
|
||||
MaxShortLength = 20
|
||||
)
|
||||
|
||||
type ShortService struct {
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
package shortutil
|
||||
|
||||
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" // 64 possibilities
|
|
@ -3,16 +3,22 @@ package shortutil
|
|||
|
||||
import (
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
letterIdxBits = 7 // 7 bits to represent a letter index
|
||||
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
|
||||
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
||||
// These are the characters that can be used in shorts
|
||||
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" // 36 possibilities
|
||||
const alphabetLen = int64(len(alphabet))
|
||||
|
||||
var (
|
||||
letterIdxBits = len(strconv.FormatInt(alphabetLen, 2)) // number of bits to represent alphabetLen
|
||||
letterIdxMask = int64(1<<letterIdxBits - 1) // All 1-bits, as many as letterIdxBits
|
||||
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
||||
)
|
||||
|
||||
// src is the random source for generating shorts
|
||||
var src = rand.NewSource(time.Now().UnixNano())
|
||||
|
||||
func GenerateRandomShort(n int) string {
|
||||
|
|
Loading…
Reference in New Issue
Block a user