From b0a5cac0c80a84e934037ec1e950da63dedcaa5b Mon Sep 17 00:00:00 2001 From: guzeng Date: Thu, 24 Jun 2021 16:38:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- header.go | 8 +++++--- weekday.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 weekday.go diff --git a/header.go b/header.go index d7d5f0c..a037314 100644 --- a/header.go +++ b/header.go @@ -42,9 +42,11 @@ func GetDomain(req *http.Request) string { scheme = "https://" } var host string = GetHost(req) - - host = strings.Split(host, ":")[0] - + hosts := strings.Split(host, ":") + host = hosts[0] + if hosts[1] == "443" { + scheme = "https://" + } var w strings.Builder w.WriteString(scheme) w.WriteString(host) diff --git a/weekday.go b/weekday.go new file mode 100644 index 0000000..e8440b7 --- /dev/null +++ b/weekday.go @@ -0,0 +1,54 @@ +package helper + +import ( + "strconv" + "strings" + "time" +) + +/** + * 星期几索引化 + * 2021/02/24 + * gz + */ +func GetWeekday() string { + week := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} + + var index int + + today := time.Now().Weekday().String() + + for key, day := range week { + if day == today { + index = key + break + } + } + + return strconv.Itoa(index) +} + +/** + * 今天是否可用 + * weekdays 0,1,2,4 + * 2021/02/24 + * gz + */ +func TodayCanUse(weekdays string) bool { + + if weekdays == "" { + return true + } + days := strings.Split(weekdays, ",") + + var can bool = false + today := GetWeekday() + for _, day := range days { + if today == day { + can = true + break + } + } + + return can +}