Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shgopher/short

URL shortening service. 高性能短链接服务。
https://github.com/shgopher/short

docker gin go go-micro k8s mysql redis rocketmq shortening-urls url vue

Last synced: 2 months ago
JSON representation

URL shortening service. 高性能短链接服务。

Awesome Lists containing this project

README

        

# short

URL shortening service.

## Usage
[example](./example/example.go)
```go
package main

import (
"fmt"
"github.com/golang/glog"
"github.com/googege/short"
"os"
)

var (
path = "https://t.cn/"
longURL = "https://github.com/googege/GOFamily/blob/master/%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/%E7%AE%97%E6%B3%95/%E7%AE%97%E6%B3%95%E9%A2%98/leetcode/1.md"
)

func main() {
db := short.NewMapDB()
// add db engine to short.
s := short.NewShort(db)
//
shortURL, err := s.ShortAdd(longURL)
if err != nil {
glog.Error(err)
} else {
fmt.Println(shortURL)
}
//
longURL, err = s.ShortFind(path + shortURL)
// if http
//http.Redirect(nil,nil,longURL,302
//)
if err != nil {
glog.Error(err)
} else {
fmt.Println("longURL:", longURL)
}
//
shortURL, err = s.ShortFind("a")
if err != nil {
glog.Error(err)
} else {
fmt.Println("short: ", shortURL)
}
//
file, err := os.Getwd()
if err != nil {
glog.Error(err)
}
if err = s.SetQR(path, 256, file+"/text.png"); err != nil {
glog.Error(err)
}
}

```

## HERE
微信公众号:科科人神

关注我了解更多软件知识。