Initial import.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
kls.conf
|
||||
30
links/alphabet.go
Normal file
30
links/alphabet.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package links
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
const codeLength = 5
|
||||
|
||||
var (
|
||||
alphabet = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"
|
||||
alphabetLength = big.NewInt(int64(len(alphabet)))
|
||||
)
|
||||
|
||||
func randInt() int {
|
||||
p, err := rand.Int(rand.Reader, alphabetLength)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
return int(p.Int64())
|
||||
}
|
||||
|
||||
func GenCode() string {
|
||||
var code []byte
|
||||
for i := 0; i < codeLength; i++ {
|
||||
code = append(code, alphabet[randInt()])
|
||||
}
|
||||
return string(code)
|
||||
}
|
||||
7
schema.sql
Normal file
7
schema.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE urls (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
url TEXT NOT NULL,
|
||||
nurl TEXT NOT NULL, -- normalized url
|
||||
short TEXT NOT NULL UNIQUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT
|
||||
);
|
||||
Reference in New Issue
Block a user