Compare commits
5 Commits
7394c1b49e
...
v0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
17a9c5835e
|
|||
|
b8766e37c1
|
|||
|
fb8825249a
|
|||
|
961d8ecbb0
|
|||
|
ca29d9fe53
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
|||||||
data/
|
data/
|
||||||
./shortify/
|
shortify/
|
||||||
|
|||||||
7
LICENSE
Normal file
7
LICENSE
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Copyright 2025 Tijl
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.tijl.dev/tijl/shortify"
|
"git.tijl.dev/tijl/shortify"
|
||||||
|
"git.tijl.dev/tijl/shortify/pkg/generation"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,6 +16,9 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// example decoding
|
||||||
|
fmt.Println(generation.DecodeBase62("11uPoqA1W"))
|
||||||
|
|
||||||
// listen the admin interface
|
// listen the admin interface
|
||||||
|
|
||||||
unixListener, err := shortify.GetUnixListener("./shortify/admin.sock")
|
unixListener, err := shortify.GetUnixListener("./shortify/admin.sock")
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
idSize = 4 // 4 bytes for random part
|
idSize = 6 // 4 bytes for random part
|
||||||
prefixSize = 2 // 2 bytes for client prefix
|
prefixSize = 2 // 2 bytes for client prefix
|
||||||
rawIDLength = prefixSize + idSize // total 6 bytes
|
rawIDLength = prefixSize + idSize // total 6 bytes
|
||||||
base62Len = 8 // 6 bytes encoded in base62 ~ 8 chars
|
//base62Len = 8 // 6 bytes encoded in base62 ~ 8 chars
|
||||||
poolSize = 10000
|
poolSize = 10000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
3
serve.go
3
serve.go
@@ -23,6 +23,9 @@ func (s *Server) Admin() *fiber.App {
|
|||||||
|
|
||||||
a.Post("/shorten", func(c *fiber.Ctx) error {
|
a.Post("/shorten", func(c *fiber.Ctx) error {
|
||||||
shortUrl := c.Query("s")
|
shortUrl := c.Query("s")
|
||||||
|
if shortUrl == "" {
|
||||||
|
shortUrl = s.serverGen.NextID()
|
||||||
|
}
|
||||||
longUrl := string(c.Body())
|
longUrl := string(c.Body())
|
||||||
|
|
||||||
return s.storage.Put(shortUrl, longUrl)
|
return s.storage.Put(shortUrl, longUrl)
|
||||||
|
|||||||
Reference in New Issue
Block a user