url-shortenter

module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2023 License: MIT

README

URL-Shortenter

Go Reference Go-Url-Shortenter CI License GitHub go.mod Go version (branch)

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.

快速使用

go install -u -v github.com/houseme/url-shortenter@latest

Console 后台默认帐号

默认帐号: urlShortener
默认密码: B9Mazv5M2J6%1zU2@nxC

数据库中存储的是加密后的密码,在 document\structure.sql 中标有注释,如果需要自定义其他密码,可以修改这里

加密规则 utility/helper.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 须携带

 Authorization: Bearer {sha256_of_password}
1. 新增短链接 POST /api/url

短链接生产过程相关代码

所在文件 utility/helper.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))
	g.Log(logger).Debug(ctx, "utilHelper GenerateShortLink str:", str, " number:", number)
	return str[:8], nil
}

Directories

Path Synopsis
app
console
Package main is the main package for the console service.
Package main is the main package for the console service.
console/internal/packed
Package packed is a packed service.
Package packed is a packed service.
front
Package main is the main entry of the application.
Package main is the main entry of the application.
front/internal/consts
Package consts
Package consts
Package home
front/internal/logic/middleware
Package middleware .
Package middleware .
front/internal/model
Package model
Package model
front/internal/service
Package service provides the business logic for the front service.
Package service provides the business logic for the front service.
schedule
Package main is the main package for the schedule service.
Package main is the main package for the schedule service.
schedule/internal/logic/lark
Package lark is a lark service.
Package lark is a lark service.
schedule/internal/logic/short
Package short is a short service.
Package short is a short service.
internal
alibaba
Package alibaba is a utility package for Alibaba.
Package alibaba is a utility package for Alibaba.
captcha
Package captcha is a utility package for captcha.
Package captcha is a utility package for captcha.
crawler
Package crawler is a utility package for crawler.
Package crawler is a utility package for crawler.
tencent
Package tencent is a utility package for Tencent.
Package tencent is a utility package for Tencent.
tracing
Package tracing is a utility package for tracing.
Package tracing is a utility package for tracing.
webhooks/lark
Package lark is a utility package for Lark.
Package lark is a utility package for Lark.
Package utility is a utility package for utility.
Package utility is a utility package for utility.
cache
Package cache is a utility package for cache.
Package cache is a utility package for cache.
env
Package env is a utility package for env.
Package env is a utility package for env.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL