初始化项目文件
This commit is contained in:
34
api_iris/utils/sudoku.go
Normal file
34
api_iris/utils/sudoku.go
Normal file
@ -0,0 +1,34 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func CheckSudoku(sudoku string) (error, ResSudoku) {
|
||||
resp, err := http.Get(fmt.Sprintf("https://git-ylsa0.cn/api_ylsa/get_sudoku_check/?sudoku=%s", url.QueryEscape(sudoku)))
|
||||
if err != nil {
|
||||
logrus.Errorln("请求get_sudoku_check接口失败:", err)
|
||||
return err, ResSudoku{}
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
err = Body.Close()
|
||||
if err != nil {
|
||||
logrus.Errorln(err.Error())
|
||||
}
|
||||
}(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
var r ResSudoku
|
||||
//解析json结构
|
||||
err = json.Unmarshal(body, &r)
|
||||
if err != nil {
|
||||
logrus.Errorln("请求结果json解析失败:", err)
|
||||
return err, ResSudoku{}
|
||||
}
|
||||
logrus.Infoln("数独检查完成")
|
||||
return nil, r
|
||||
}
|
Reference in New Issue
Block a user