mirror of https://gitee.com/openkylin/genmai.git
完成json格式解析功能
This commit is contained in:
parent
115e64e342
commit
cad98875d3
|
@ -14,7 +14,7 @@
|
|||
"References": [ "Reference1", "Reference2" ],
|
||||
"SiteClassification": {
|
||||
"CvssMetrics": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
|
||||
"CvssScore": "7.8",
|
||||
"CvssScore": 7.8,
|
||||
"CveId": "CVE-2021-22555",
|
||||
"CweId": "CWE-787",
|
||||
"CnvdId": "None",
|
||||
|
@ -26,11 +26,11 @@
|
|||
"SiteRequests": {
|
||||
"Implement": {
|
||||
"RawTypes": [ "implementOne", "implementSec" ],
|
||||
"ImMap": "",
|
||||
"ImMap": {},
|
||||
"ImplementFirst": "./src/Actuator/CVE-2022-22555/CVE-2021-22555_x86_64",
|
||||
"Condition": "None"
|
||||
},
|
||||
"ReqCondition": "true",
|
||||
"ReqCondition": true,
|
||||
"Matchers": {
|
||||
"Types": [
|
||||
"dsl"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"References": [ "Reference1", "Reference2" ],
|
||||
"SiteClassification": {
|
||||
"CvssMetrics": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
|
||||
"CvssScore": "7.8",
|
||||
"CvssScore": 7.8,
|
||||
"CveId": "CVE-2021-22555",
|
||||
"CweId": "CWE-787",
|
||||
"CnvdId": "None",
|
||||
|
@ -26,11 +26,11 @@
|
|||
"SiteRequests": {
|
||||
"Implement": {
|
||||
"RawTypes": [ "implementOne", "implementSec" ],
|
||||
"ImMap": "",
|
||||
"ImMap": {},
|
||||
"ImplementFirst": "./src/Actuator/CVE-2022-22555/CVE-2021-22555_x86_64",
|
||||
"Condition": "None"
|
||||
},
|
||||
"ReqCondition": "true",
|
||||
"ReqCondition": true,
|
||||
"Matchers": {
|
||||
"Types": [
|
||||
"dsl"
|
||||
|
|
|
@ -32,7 +32,6 @@ import (
|
|||
"os"
|
||||
"io"
|
||||
"strings"
|
||||
"fmt"
|
||||
json "encoding/json"
|
||||
)
|
||||
|
||||
|
@ -42,7 +41,7 @@ type ConfigParserJSON map[string]interface {}
|
|||
|
||||
///////////////////////////////
|
||||
// override functions
|
||||
func (cpy *ConfigParserJSON)parse(file string) (rc error) {
|
||||
func (cpj *ConfigParserJSON)parse(file string) (rc error) {
|
||||
configfile, ok := os.Open(file)
|
||||
rc = ok;
|
||||
/* */
|
||||
|
@ -57,9 +56,40 @@ func (cpy *ConfigParserJSON)parse(file string) (rc error) {
|
|||
|
||||
rc = json.Unmarshal(json_bytes, &config)
|
||||
|
||||
fmt.Println(configfile)
|
||||
fmt.Println(">>>json>>>")
|
||||
fmt.Println(config)
|
||||
(*cpj) = config
|
||||
|
||||
return rc
|
||||
}
|
||||
|
||||
func (cpj *ConfigParserJSON)mashal(file string) (rc error) {
|
||||
if (nil == cpj) {
|
||||
rc = ERR_EMPTY_INTERFACE
|
||||
return rc
|
||||
} // if (nil == cpj ...
|
||||
|
||||
if ("" == file) {
|
||||
rc = ERR_EMPTY_FILE
|
||||
return rc
|
||||
} // if ("" == file
|
||||
|
||||
if ( (strings.HasSuffix(file, ".json")) ) {
|
||||
rc = cpj.parse(file)
|
||||
// if ( (0 == len("")) &&
|
||||
// (nil == err) ) {
|
||||
// cpjs := &ConfigParserJSON{}
|
||||
// cpj = cpjs
|
||||
// return cpj.parse(file)
|
||||
// } // if ( (0 ...
|
||||
|
||||
return rc
|
||||
} // if ( (strings ...
|
||||
|
||||
rc = ERR_STYLE
|
||||
return rc
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
// member functions
|
||||
func (cpj *ConfigParserJSON)Parse(file string) (rc error) {
|
||||
return cpj.parse(file)
|
||||
}
|
||||
|
|
|
@ -71,12 +71,12 @@ func (cpy *ConfigParserYAML)parse(file string) (rc error) {
|
|||
func (cpy *ConfigParserYAML)mashal(file string) (rc error) {
|
||||
if (nil == cpy) {
|
||||
rc = ERR_EMPTY_INTERFACE
|
||||
return
|
||||
return rc
|
||||
} // if (nil == cpy ...
|
||||
|
||||
if ("" == file) {
|
||||
rc = ERR_EMPTY_FILE
|
||||
return
|
||||
return rc
|
||||
} // if ("" == file
|
||||
|
||||
if ( (strings.HasSuffix(file, ".yaml")) ||
|
||||
|
@ -89,11 +89,11 @@ func (cpy *ConfigParserYAML)mashal(file string) (rc error) {
|
|||
// return cpy.parse(file)
|
||||
// } // if ( (0 ...
|
||||
|
||||
return
|
||||
return rc
|
||||
} // if ( (strings ...
|
||||
|
||||
rc = ERR_STYLE
|
||||
return
|
||||
return rc
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
|
|
@ -8,8 +8,10 @@
|
|||
// Compiler: go
|
||||
//
|
||||
// Author: alpha
|
||||
// songbangchengjin
|
||||
// Organization: alpha
|
||||
// Contacts: chenxinquan@kylinos.com
|
||||
// songbangchengjin@kylinos.com
|
||||
//
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ func Test() {
|
|||
// YAML common
|
||||
config := ConfigParserYAML{}
|
||||
config.mashal("/home/alpha/Developments/kylinprojects/genmai/data/common/CVE-2021-3156.yaml")
|
||||
fmt.Println(">>")
|
||||
fmt.Println("\n>>YAML>>\n")
|
||||
fmt.Print(config)
|
||||
|
||||
mystruct := ConfigKernel{}
|
||||
|
@ -66,6 +66,8 @@ func Test() {
|
|||
json_config_c := ConfigParserJSON{}
|
||||
json_config_c.mashal("/home/alpha/Developments/kylinprojects/genmai/data/common/CVE-2021-3156.json")
|
||||
// json_config_c.mashal("/home/alpha/Developments/kylinprojects/genmai/data/common/Sample1.json")
|
||||
fmt.Println("\n>>JSON>>\n")
|
||||
fmt.Print(json_config_c)
|
||||
|
||||
json_struct := ConfigKernel{}
|
||||
json_err := mapstructure.Decode(json_config_c, &json_struct)
|
||||
|
|
Loading…
Reference in New Issue