-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexample.go
More file actions
62 lines (58 loc) · 1.2 KB
/
Copy pathexample.go
File metadata and controls
62 lines (58 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* @Author: shgopher shgopher@gmail.com
* @Date: 2023-05-26 04:15:12
* @LastEditors: shgopher shgopher@gmail.com
* @LastEditTime: 2023-05-26 04:33:30
* @FilePath: /short/example/example.go
* @Description:
*
* Copyright (c) 2023 by shgopher, All Rights Reserved.
*/
package main
import (
"fmt"
"os"
"github.com/golang/glog"
"github.com/shgopher/short"
)
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)
}
}