Support return https

This commit is contained in:
CareyWong 2020-03-24 18:32:21 +08:00
parent e013ce5889
commit 196788ea2b

View File

@ -53,6 +53,7 @@ func main() {
ttl := flag.Int("ttl", defaultExpire, "短链接有效期,单位(天)默认90天。") ttl := flag.Int("ttl", defaultExpire, "短链接有效期,单位(天)默认90天。")
conn := flag.String("conn", defaultRedisConfig, "Redis连接格式: host:port") conn := flag.String("conn", defaultRedisConfig, "Redis连接格式: host:port")
passwd := flag.String("passwd", "", "Redis连接密码") passwd := flag.String("passwd", "", "Redis连接密码")
https := flag.Int("https", 0, "是否返回 https 短链接")
flag.Parse() flag.Parse()
if *domain == "" { if *domain == "" {
@ -100,7 +101,13 @@ func main() {
log.Println(longUrl, shortKey) log.Println(longUrl, shortKey)
res.LongUrl = longUrl res.LongUrl = longUrl
res.ShortUrl = "http://" + *domain + "/" + shortKey
protocol := "http://"
if *https != 0 {
protocol = "https://"
}
res.ShortUrl = protocol + *domain + "/" + shortKey
context.JSON(200, *res) context.JSON(200, *res)
}) })