Files
web_ylsa/api_iris/utils/sudoku.go
2025-07-11 16:54:11 +08:00

35 lines
776 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}