42 lines
969 B
Go
42 lines
969 B
Go
package action
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
"git.lxtend.com/lixiangwuxian/qqbot/config"
|
|
"git.lxtend.com/lixiangwuxian/qqbot/constants"
|
|
"git.lxtend.com/lixiangwuxian/qqbot/model"
|
|
)
|
|
|
|
var loginAccountInfo *model.LoginAccountInfoResponse = nil
|
|
|
|
func GetLoginAccountInfo() (*model.LoginAccountInfoResponse, error) {
|
|
if loginAccountInfo != nil {
|
|
return loginAccountInfo, nil
|
|
}
|
|
fullURL := fmt.Sprintf("http://%s%s", config.ConfigManager.GetConfig().Management.NapcatHttpSrv, constants.GET_LOGIN_INFO)
|
|
|
|
response, err := http.Post(fullURL, "application/json", nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
body, err := io.ReadAll(response.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var loginAccountInfoResponse model.LoginAccountInfoResponse
|
|
err = json.Unmarshal(body, &loginAccountInfoResponse)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
loginAccountInfo = &loginAccountInfoResponse
|
|
return loginAccountInfo, nil
|
|
}
|