Giter Club home page Giter Club logo

houseme / url-shortenter Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 2.0 3.65 MB

A short link service system suitable for small and medium-sized community websites. supports short link production, query and 302 redirection, and comes with click statistics, independent IP statistics and access logs.

Home Page: https://houseme.github.io/url-shortenter/

License: MIT License

Go 100.00%
golang productivity screenshot short-urls shorturl shorturl-services url-shortener urlshortener api authorization

url-shortenter's Introduction

URL-Shortenter

Go Reference 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 后台默认帐号

默认帐号:shortenter
默认密码: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))
    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, 100% free and open-source, forever.

Thinks

JetBrains

url-shortenter's People

Contributors

dependabot[bot] avatar houseme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

daheige

url-shortenter's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.