Skip to content

Commit

Permalink
feat:增加常量,doGet函数
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyIsMe committed Oct 16, 2022
1 parent 97b06ab commit d55e85e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
15 changes: 15 additions & 0 deletions constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const (

TypeAdd = 1
TypeMinus = -1

StartTime = "00:00:00"
EndTime = "23:59:59"
)

const (
Expand Down Expand Up @@ -58,3 +61,15 @@ var WeekDayMap = map[string]string{
"Saturday": "周六",
"Sunday": "周日",
}

const (
DayVIP = "日会员"
MonthVIP = "月会员"
QuarterVIP = "季会员"
YearVIP = "年会员"

DayAllVIP = "日大会员"
MonthAllVIP = "月大会员"
QuarterAllVIP = "季大会员"
YearAllVIP = "年大会员"
)
5 changes: 3 additions & 2 deletions constant/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const (
const (
StrconvAtoiError = 30000 // 类型转换错误(主要是string转int)
ParseTimeError = 30001 // 日期类型的错误
ReadFileError = 30002
UnknowError = 30003
ReadFileError = 30002 // 读取文件错误
UnknowError = 30003 // 未知错误
UnknowOwner = 30004 // 不是球馆管理员返回码
)

// 返回4xxxx -> json错误
Expand Down
33 changes: 33 additions & 0 deletions http/http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package http

import (
"crypto/tls"
"encoding/json"
"io/ioutil"
"log"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -25,3 +29,32 @@ func Cors() gin.HandlerFunc {
c.Next()
}
}

// DoGet get请求
func DoGet(req *http.Request) (map[string]string, error) {
req.Header.Set("Content-Type", "application/json")
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}

rsp, err := client.Do(req)
if err != nil {
log.Printf("getToken client.Do err: [%+v]", err)
return nil, err
}
defer rsp.Body.Close()

body, _ := ioutil.ReadAll(rsp.Body)
rspMap := make(map[string]string)
err = json.Unmarshal(body, &rspMap)
if err != nil {
log.Printf("Unmarshal rsp body err:[%+v]", err)
return nil, nil
}

return rspMap, nil
}

0 comments on commit d55e85e

Please sign in to comment.