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 +}