From 196788ea2b10b725d03720ef335966163129f7e8 Mon Sep 17 00:00:00 2001 From: CareyWong Date: Tue, 24 Mar 2020 18:32:21 +0800 Subject: [PATCH] Support return https --- main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 7e375a0..ffec775 100644 --- a/main.go +++ b/main.go @@ -53,6 +53,7 @@ func main() { ttl := flag.Int("ttl", defaultExpire, "短链接有效期,单位(天),默认90天。") conn := flag.String("conn", defaultRedisConfig, "Redis连接,格式: host:port") passwd := flag.String("passwd", "", "Redis连接密码") + https := flag.Int("https", 0, "是否返回 https 短链接") flag.Parse() if *domain == "" { @@ -100,7 +101,13 @@ func main() { log.Println(longUrl, shortKey) res.LongUrl = longUrl - res.ShortUrl = "http://" + *domain + "/" + shortKey + + protocol := "http://" + if *https != 0 { + protocol = "https://" + } + res.ShortUrl = protocol + *domain + "/" + shortKey + context.JSON(200, *res) })