mirror of
https://github.com/aykhans/oh-my-url.git
synced 2025-07-02 00:56:47 +00:00
🎉 first commit
This commit is contained in:
26
app/utils/short_key.go
Normal file
26
app/utils/short_key.go
Normal file
@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const keyCharacters string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
func GenerateKey(n int) string {
|
||||
var result strings.Builder
|
||||
base := len(keyCharacters)
|
||||
|
||||
for n > 0 {
|
||||
n--
|
||||
result.WriteByte(keyCharacters[n%base])
|
||||
n /= base
|
||||
}
|
||||
|
||||
key := result.String()
|
||||
runes := []rune(key)
|
||||
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
|
||||
runes[i], runes[j] = runes[j], runes[i]
|
||||
}
|
||||
|
||||
return string(runes)
|
||||
}
|
19
app/utils/templates.go
Normal file
19
app/utils/templates.go
Normal file
@ -0,0 +1,19 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func GetTemplatePaths(filenames ...string) []string {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
templatePath := filepath.Join(dir, "app", "templates")
|
||||
for i, filename := range filenames {
|
||||
filenames[i] = filepath.Join(templatePath, filename)
|
||||
}
|
||||
return filenames
|
||||
}
|
Reference in New Issue
Block a user