Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: optimize the code, update go api and godoc #14

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/go-toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 3 additions & 4 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"os"
"time"

"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 18 additions & 7 deletions now/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
6 changes: 1 addition & 5 deletions pwd/pwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading