Skip to content

Commit

Permalink
修改配置文件读取结构
Browse files Browse the repository at this point in the history
  • Loading branch information
nyancatda committed Mar 7, 2022
1 parent 7c973d5 commit 4660d43
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions HttpAPI/API/Query.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* @Author: NyanCatda
* @Date: 2021-11-06 21:49:39
* @LastEditTime: 2022-01-24 19:38:10
* @LastEditTime: 2022-03-07 19:51:39
* @LastEditors: NyanCatda
* @Description: 查询Wiki信息
* @FilePath: \ShionBot\src\HttpAPI\API\Query.go
* @FilePath: \ShionBot\HttpAPI\API\Query.go
*/
package API

Expand All @@ -21,7 +21,7 @@ import (
func QueryInfo(c *gin.Context) map[string]interface{} {
title := c.DefaultQuery("title", "")
Config := ReadConfig.GetConfig
MainWikiName := Config.Wiki.([]interface{})[0].(map[interface{}]interface{})["WikiName"].(string)
MainWikiName := Config.Wiki[0].WikiName
WikiName := c.DefaultQuery("wiki_name", MainWikiName)
var Messagejson Struct.WebHookJson
WikiLink := ReadConfig.GetWikiLink("HttpAPI", Messagejson, WikiName)
Expand Down
8 changes: 4 additions & 4 deletions Modular/GetWikiInfo/GetWikiInfo.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: NyanCatda
* @Date: 2021-10-03 02:14:31
* @LastEditTime: 2022-03-07 19:43:03
* @LastEditTime: 2022-03-07 19:50:40
* @LastEditors: NyanCatda
* @Description: 获取Wiki页面信息
* @FilePath: \ShionBot\Modular\GetWikiInfo\GetWikiInfo.go
Expand Down Expand Up @@ -64,8 +64,8 @@ func WikiNameExist(WikiName string, SNSName string, Messagejson Struct.WebHookJs

Config := ReadConfig.GetConfig
var ConfigWikiName string
for one := range Config.Wiki.([]interface{}) {
ConfigWikiName = Config.Wiki.([]interface{})[one].(map[interface{}]interface{})["WikiName"].(string)
for _, one := range Config.Wiki {
ConfigWikiName = one.WikiName
if find := strings.Contains(WikiName, ConfigWikiName); find {
return true
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func GeiMainWikiName(SNSName string, Messagejson Struct.WebHookJson) string {
*/

Config := ReadConfig.GetConfig
MainWikiName := Config.Wiki.([]interface{})[0].(map[interface{}]interface{})["WikiName"].(string)
MainWikiName := Config.Wiki[0].WikiName
return MainWikiName
}

Expand Down
11 changes: 7 additions & 4 deletions Utils/ReadConfig/ConfigStruct.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* @Author: NyanCatda
* @Date: 2022-01-24 19:35:15
* @LastEditTime: 2022-01-24 19:35:16
* @LastEditTime: 2022-03-07 19:48:36
* @LastEditors: NyanCatda
* @Description: 配置文件结构体
* @FilePath: \ShionBot\src\Utils\ReadConfig\ConfigStruct.go
* @FilePath: \ShionBot\Utils\ReadConfig\ConfigStruct.go
*/
package ReadConfig

Expand Down Expand Up @@ -36,5 +36,8 @@ type Config struct {
Token string `yaml:"Token"`
} `yaml:"KaiHeiLa"`
} `yaml:"SNS"`
Wiki interface{} `yaml:"Wiki"`
}
Wiki []struct {
WikiName string `yaml:"WikiName"`
WikiLink string `yaml:"WikiLink"`
} `yaml:"Wiki"`
}
10 changes: 5 additions & 5 deletions Utils/ReadConfig/ReadConfig.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* @Author: NyanCatda
* @Date: 2021-10-03 04:14:10
* @LastEditTime: 2022-01-24 19:54:41
* @LastEditTime: 2022-03-07 19:50:26
* @LastEditors: NyanCatda
* @Description: 读取配置文件
* @FilePath: \ShionBot\src\Utils\ReadConfig\ReadConfig.go
* @FilePath: \ShionBot\Utils\ReadConfig\ReadConfig.go
*/
package ReadConfig

Expand Down Expand Up @@ -97,10 +97,10 @@ func GetWikiLink(SNSName string, Messagejson Struct.WebHookJson, WikiName string

Config := GetConfig
var ConfigWikiName string
for one := range Config.Wiki.([]interface{}) {
ConfigWikiName = Config.Wiki.([]interface{})[one].(map[interface{}]interface{})["WikiName"].(string)
for _, one := range Config.Wiki {
ConfigWikiName = one.WikiName
if ConfigWikiName == WikiName {
return Config.Wiki.([]interface{})[one].(map[interface{}]interface{})["WikiLink"].(string)
return one.WikiLink
}
}
return ""
Expand Down

0 comments on commit 4660d43

Please sign in to comment.