Home
Softono
link-shorter

link-shorter

Open source TypeScript
16
Stars
2
Forks
0
Issues
2
Watchers
3 years
Last Commit

About link-shorter

缩短网址,让分享更简单 Shorten Link, Make Sharing Simpler

Platforms

Web Self-hosted

Languages

TypeScript

Shorten Link

缩短网址,让分享更简单
Shorten Link, Make Sharing Simpler


Live Demo


简体中文 | English


Features

  • ⚡️ qwik 从源头上加速SSR应用

  • 📦 iris 一个高性能、易用且功能强大的Go语言Web框架

  • 🔎 bolt 一个高效的、嵌入式的、持久化的键值存储数据库, 只是不想用太重的mysql和redis~

  • 🎨 TaliWindCss 原子类CSS框架的祖师爷

  • 😃 daisyui 使用 Tailwind CSS 但少写类名

  • ☁️ Deploy on Netlify, zero-config

  • 🦾 Golang, of course

  • 🦾 TypeScript, of course


功能介绍-qwik部分

  • 全局变量管理
  • I18n多语言切换

功能介绍-iris部分

记录请求日志,写入本地文件

{
  "timestamp": "2023-01-21 21:15:03",
  "latency": 405000,
  "code": 200,
  "method": "GET",
  "path": "/ping",
  "ip": "::1",
  "bytes_sent": 4
}

管理端JWT身份校验

app.Post("/login", s.Login)
admin := app.Party("/admin")
{
    admin.UseRouter(jwtMiddle.Serve)
    admin.Post("/flush", s.Flush)
    admin.Get("/all", s.All)
    admin.Post("/del", s.DelOne)
}

依赖注入,降低耦合

{
...
app.RegisterDependency(shortService)
...
app.ConfigureContainer(func(api *iris.APIContainer) {
  api.Post("/short", s.ShortLink)
  api.Get("/u/{key}", s.GetRaw)
})}
...
func (s ShorterCtl) GetRaw(ctx iris.Context, ss *service.ShorterService) {
    key := ctx.Params().Get("key")
    link, err := ss.GetRaw(key)
    if err != nil {
        CommonResponse{}.Fail().SetData(err.Error()).Send(ctx)
        return
    }
    ctx.Redirect(link, iris.StatusMovedPermanently)
    return
}

路由自测,成为一名可爱的后端

var commonSchema = `{
            "type": "object",
            "properties": {
                "code":  {"type": "number"},
                "msg":   {"type": "string"},
                "data":  {"type": ["object","string"]}},
            "required": ["code", "msg", "data"]
        }`

func TestAdminApi(t *testing.T) {
    app := NewApp()
    e := httptest.New(t, app)
    e.GET("/admin/all").Expect().Status(httptest.StatusOK).
        JSON().Schema(commonSchema)
}

相关资料

golang

qwik