Browse Source

修改获取域名方法

master v0.1.1
guzeng 3 years ago
parent
commit
b0a5cac0c8
2 changed files with 59 additions and 3 deletions
  1. +5
    -3
      header.go
  2. +54
    -0
      weekday.go

+ 5
- 3
header.go View File

@ -42,9 +42,11 @@ func GetDomain(req *http.Request) string {
scheme = "https://" scheme = "https://"
} }
var host string = GetHost(req) 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 var w strings.Builder
w.WriteString(scheme) w.WriteString(scheme)
w.WriteString(host) w.WriteString(host)


+ 54
- 0
weekday.go View File

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

Loading…
Cancel
Save