# tispector
## SQL 审核平台 


## 系统构建

获取依赖包
```
go mod tidy
```

## 如何启动
请先使用dao文件夹下的build_table.sql建立相关表
config 包下确定配置文件名是否正确 (测试使用 config-example.yml) :
```go
const (
	configPathEnv = "config_path"
	configPath    = "./config/config.yml"
)
```

修改配置文件 config.yml 中 db 对象：
```go
db:
  address: "127.0.0.1"
  port: 3306
  user: "root"
  password: "123456"
  db_name: "tispector"
  max_idle_conn: 2
  max_open_conn: 30

```

启动 main.go
```go
func main() {
	flag.Parse()
	log.Println("version:", Version)
	config.InitConfig("")
	logger.InitLog(config.Conf.Server.LogDir, "tispector.log", config.Conf.Server.LogLevel)
	dao.InitDB()
	injection.Injection()
	checker.InitRuleStatus()

	router.Run()
}

```

## 规则配置文件使用

rules.yml规则配置文件在主目录的config文件夹下，配置范例如下

```yaml
# 规则:
#   Item: 规则代号
#   Name: 规则名称
#   Summary: 规则摘要
#   Close: 规则开关，1为开，0为关，其他值默认关闭
#   Level: 规则告警等级
#   Threshold: 一个可定义的阈值，当规则需要定义阈值时可修改使用
#   CheckFunc: 规则对应函数名
#   Case: SQL样例

RuleCreate001:
  Item: "Create.001"
  Name: "injection check character set"
  Summary: "表必须指定utf8mb4字符集若指定collate则必须为utf8mb4_bin"
  Close: 1
  Level: 1
  Threshold: 0
  CheckFunc: "RuleCreateTableCharset"
  Case:
```



```go
const (
	// rulePath 规则配置文件路径
	rulePath = "./config/rules.yml"
)
```

