-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.md
81 lines (59 loc) · 2.65 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# URL-Shortenter
[![Go Reference](https://pkg.go.dev/badge/github.com/houseme/url-shortenter.svg)](https://pkg.go.dev/github.com/houseme/url-shortenter)
[![Url-Shortenter CI](https://github.com/houseme/url-shortenter/actions/workflows/go.yml/badge.svg)](https://github.com/houseme/url-shortenter/actions/workflows/go.yml)
[![License](https://img.shields.io/github/license/houseme/url-shortenter.svg?style=flat)](https://github.com/houseme/url-shortenter)
![GitHub go.mod Go version (branch)](https://img.shields.io/github/go-mod/go-version/houseme/url-shortenter/main)
A short link service system suitable for small and medium-sized community websites.
Support short link production, query and 302 redirection, and have its own click statistics, independent IP statistics,
access log query.
## 快速使用
```shell
go install -u -v github.com/houseme/url-shortenter@latest
```
## Console 后台默认帐号
默认帐号:`shortenter`
默认密码:`B9Mazv5M2J6%1zU2@nxC`
数据库中存储的是加密后的密码,在 `document\structure.sql` 中标有注释,如果需要自定义其他密码,可以修改这里
加密规则 `utility/helper.go` 中
```go
func (u *utilHelper) PasswordBase58Hash(password string) (string, error) {
data, err := u.Sha256OfShort(password)
if err != nil {
err = gerror.Wrap(err, "utilHelper PasswordBase58Hash Sha256OfShort error")
return "", err
}
return u.Base58Encode(data), nil
}
```
## HTTP API 支持
### `/api` 接口权限说明
所有 `/console/api/*` 接口需要通过 `Bearer Token` 方式验证权限,亦即:每个请求 Header 须携带
```shell
Authorization: Bearer {sha256_of_password}
```
### 1. 新增短链接 `POST /api/url`
## 短链接生产过程相关代码
所在文件 `utility/helper.go`
```go
func (u *utilHelper) GenerateShortLink(ctx context.Context, url string) (string, error) {
var (
err error
urlHash []byte
logger = u.Logger(ctx)
)
g.Log(logger).Debug(ctx, "utilHelper GenerateShortLink url:", url)
if urlHash, err = u.Sha256OfShort(url); err != nil {
err = gerror.Wrap(err, "utilHelper GenerateShortLink Sha256OfShort err")
return "", err
}
// number := new(big.Int).SetBytes(urlHash).Uint64()
// str := u.Base58Encode(gconv.Bytes(number))
str := u.Base58Encode(urlHash)
g.Log(logger).Debug(ctx, "utilHelper GenerateShortLink str:", str, " number:", number)
return str[:8], nil
}
```
## License
`URL-Shortenter` is licensed under the [MIT License](LICENSE), 100% free and open-source, forever.
## Thinks
<a href="https://www.jetbrains.com/?from=URL-Shortenter"><img src="https://goframe.org/download/thumbnails/1114119/jetbrains.png" height="120" alt="JetBrains"/></a>