diff --git a/conf/go-toml.go b/conf/go-toml.go index 18b7831..a45082d 100644 --- a/conf/go-toml.go +++ b/conf/go-toml.go @@ -25,7 +25,7 @@ func Init(filePath string, config interface{}) error { confLock.Lock() fileBytes, err := os.ReadFile(filePath) if err != nil { - log.Println("Toml init ioutil.ReadFile error: ", err) + log.Println("Toml init os.ReadFile error: ", err) return err } diff --git a/http/http.go b/http/http.go index 568d185..8601553 100644 --- a/http/http.go +++ b/http/http.go @@ -16,7 +16,6 @@ import ( "os" "time" - "io/ioutil" "mime/multipart" "net/http" "net/url" @@ -45,7 +44,7 @@ func Get(api string, args ...url.Values) ([]byte, error) { } defer resp.Body.Close() - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) } // Post http post, params is url.Values type @@ -71,7 +70,7 @@ func Post(api string, args ...interface{}) ([]byte, error) { } defer resp.Body.Close() - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) } // Api http api @@ -187,7 +186,7 @@ func PostFile(filename, targetUrl, upParam string) (string, error) { } defer resp.Body.Close() - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/now/time.go b/now/time.go index 24e4a9f..d5ac258 100644 --- a/now/time.go +++ b/now/time.go @@ -25,27 +25,33 @@ const ( RSSFormat = "Mon, 02 Jan 2006 15:04:05 -0700" ) -// Add add some time +// Add add a tm time to the begin time func Add(begin time.Time, tm string) (end time.Time) { day, _ := time.ParseDuration(tm) end = begin.Add(day) return } -// Timestamp get now timestamp +// Timestamp get the timestamp of now func Timestamp() int64 { return time.Now().Unix() } -// TimestampNano get now timestamp +// TimestampNano get the nano timestamp of now func TimestampNano() int64 { return time.Now().UnixNano() } -// GetMonTS get monday timestamp -func GetMonTS() (int64, error) { - weekTm := now.BeginningOfWeek().Format(Format) - theTime, err := time.ParseInLocation(Format, weekTm, time.Local) +// GetMonTS get the timestamp of the monday +func GetMonTS(m ...bool) (int64, error) { + var tm string + if len(m) > 0 { + tm = now.BeginningOfMonth().Format(Format) + } else { + tm = now.BeginningOfWeek().Format(Format) + } + + theTime, err := time.ParseInLocation(Format, tm, time.Local) if err != nil { return 0, err } @@ -56,3 +62,8 @@ func GetMonTS() (int64, error) { timestamp := theTime.Unix() return timestamp, nil } + +// GetMonthTS returns the timestamp of the first day of the month +func GetMonthTS() (int64, error) { + return GetMonTS(true) +} diff --git a/pwd/pwd.go b/pwd/pwd.go index dffbc0c..b37341f 100644 --- a/pwd/pwd.go +++ b/pwd/pwd.go @@ -57,11 +57,7 @@ func Bcrypt(pwd string) string { // BcryptCheck check bcrypt hash func BcryptCheck(hashedPwd, pwd string) bool { err := bcrypt.CompareHashAndPassword([]byte(hashedPwd), []byte(pwd)) - if err != nil { - return false - } - - return true + return err == nil } // Sha1 sha1.Sum