Skip to content

Commit

Permalink
feat:获取页,获取页大小
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyIsMe committed Apr 1, 2023
1 parent 721807f commit e6f167f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ func NumberHandler(results *sql.Rows) []int {
}
return numbers
}

// IsValidString 判断sql里面的数据是否合法
func IsValidString(nullString sql.NullString) string {
if nullString.Valid {
return nullString.String
}

return ""
}
45 changes: 45 additions & 0 deletions utils/common_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package utils

import (
"github.com/shootz-developer/gtool/constant"
"log"
"math"
"strconv"
)

// EarthDistance 计算距离
func EarthDistance(lat1, lng1, lat2, lng2 float64) float64 {
lat1 = lat1 * math.Pi / 180.0
lng1 = lng1 * math.Pi / 180.0
lat2 = lat2 * math.Pi / 180.0
lng2 = lng2 * math.Pi / 180.0
a := lat1 - lat2
b := lng1 - lng2
s := 2 * math.Asin(
math.Sqrt(math.Pow(math.Sin(a/2), 2)+math.Cos(lat1)*math.Cos(lat2)*math.Pow(math.Sin(b/2), 2)))
s = s * 6378.137
s = math.Round(s*10000) / 10000
return s
}

// GetPage 获取页
func GetPage(pageStr string) int {
page, err := strconv.Atoi(pageStr)
if err != nil {
log.Printf("Page string to int err: [%+v]", err)
return constant.DefaultPage
}

return page
}

// GetLimit 获取页大小
func GetLimit(pageStr string) int {
limit, err := strconv.Atoi(pageStr)
if err != nil {
log.Printf("Page string to int err: [%+v]", err)
return constant.DefaultLimit
}

return limit
}

0 comments on commit e6f167f

Please sign in to comment.