Skip to content

yu1ec/go-shorten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Shorten

最快实现短链接跳转

容器

docker pull ghcr.io/yu1ec/go-shorten:latest

Running the Application

本地运行

go mod tidy
go run cmd/main.go

The server will start on localhost:8080. You can then use the endpoints to shorten URLs.

API Endpoints

POST /shorten

参数名 类型 是否必填 说明
target_url string 目标跳转地址
short_code string 自定义短码,不传则自动生成
remark string 备注

注意:
该接口需要通过 HTTP Basic Auth 认证。
你需要在请求头中添加 Authorization: Basic xxx,其中 xxxSHORTEN_AUTH_USER:SHORTEN_AUTH_PASS 的 base64 编码。

请求示例:

{
  "target_url": "https://example.com",
  "short_code": "abc123",
  "remark": "示例"
}

curl 示例:

curl -X POST http://localhost:5768/shorten \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic $(echo -n 'xxx:pass' | base64)" \
  -d '{"target_url":"https://example.com","short_code":"abc123","remark":"示例"}'

响应:

  • 成功:200 OK,body 为短码字符串
  • 短码冲突:409 Conflict

GET /:short_code

  • 直接访问 /abc123,会跳转到对应的目标地址。
  • 未找到短码时返回 404。

快速运行

services:
  go-shorten:
    image: ghcr.io/yu1ec/go-shorten:latest
    container_name: go-shorten
    ports:
      - "5768:5768"
    environment:
      SHORTEN_AUTH_USER: xxx
      SHORTEN_AUTH_PASS: pass
    volumes:
      - ./data:/app/data
    restart: unless-stopped

简易后台管理

登录界面: http://localhost:5768/login 管理面板: http://localhost:5768/admin 短链接管理: http://localhost:5768/admin/urls 用户管理: http://localhost:5768/admin/users

About

超简单短链接服务(Super simple short link service)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages