Skip to content

Commit

Permalink
polish code before lunar new year (#193)
Browse files Browse the repository at this point in the history
* add test case  and notes

* vendor update

* use `tput setaf/srg0` set color in Makefile

* fix loadExternalResource fail cause panic
  • Loading branch information
martianzhang committed Jan 21, 2019
1 parent b1860bb commit 86afd23
Show file tree
Hide file tree
Showing 41 changed files with 12,929 additions and 6,119 deletions.
13 changes: 4 additions & 9 deletions Makefile
Expand Up @@ -18,13 +18,10 @@ BUILD_TIME=`date +%Y%m%d%H%M`
COMMIT_VERSION=`git rev-parse HEAD`

# colors compatible setting
COLOR_ENABLE=$(shell tput colors > /dev/null; echo $$?)
ifeq "$(COLOR_ENABLE)" "0"
CRED=$(shell printf "\033[91m")
CGREEN=$(shell printf "\033[92m")
CYELLOW=$(shell printf "\033[93m")
CEND=$(shell printf "\033[0m")
endif
CRED:=$(shell tput setaf 1 2>/dev/null)
CGREEN:=$(shell tput setaf 2 2>/dev/null)
CYELLOW:=$(shell tput setaf 3 2>/dev/null)
CEND:=$(shell tput sgr0 2>/dev/null)

# Add mysql version for testing `MYSQL_RELEASE=percona MYSQL_VERSION=5.7 make docker`
# MySQL 5.1 `MYSQL_RELEASE=vsamov/mysql-5.1.73 make docker`
Expand Down Expand Up @@ -161,8 +158,6 @@ pingcap-parser: tidb
.PHONY: vendor
vendor: vitess pingcap-parser
# gometalinter
# 如果有不想改的lint问题可以使用metalinter.sh加黑名单
#@bash doc/example/metalinter.sh
.PHONY: lint
lint: build
@echo "$(CGREEN)Run linter check ...$(CEND)"
Expand Down
45 changes: 21 additions & 24 deletions common/markdown.go
Expand Up @@ -44,40 +44,37 @@ func MarkdownEscape(str string) string {
return str
}

//
// loadExternalResource load js/css resource from http[s] url
func loadExternalResource(resource string) string {
var content string
var body []byte
if strings.HasPrefix(resource, "http") {
resp, err := http.Get(resource)
if err == nil {
body, err = ioutil.ReadAll(resp.Body)
if err == nil {
content = string(body)
} else {
Log.Debug("ioutil.ReadAll %s Error: %v", resource, err)
}
} else {
Log.Debug("http.Get %s Error: %v", resource, err)
if err != nil {
Log.Error("http.Get %s Error: %v", resource, err)
return content
}
defer resp.Body.Close()

body, err = ioutil.ReadAll(resp.Body)
if err != nil {
Log.Error("ioutil.ReadAll %s Error: %v", resource, err)
} else {
content = string(body)
}
} else {
fd, err := os.Open(resource)
defer func() {
err = fd.Close()
if err != nil {
Log.Error("loadExternalResource(%s) fd.Close failed: %s", resource, err.Error())
}
}()
if err == nil {
body, err = ioutil.ReadAll(fd)
if err != nil {
Log.Debug("ioutil.ReadAll %s Error: %v", resource, err)
} else {
content = string(body)
}
if err != nil {
Log.Error("os.Open %s Error: %v", resource, err)
return content
}
defer fd.Close()

body, err = ioutil.ReadAll(fd)
if err != nil {
Log.Error("ioutil.ReadAll %s Error: %v", resource, err)
} else {
Log.Debug("os.Open %s Error: %v", resource, err)
content = string(body)
}
}
return content
Expand Down
8 changes: 6 additions & 2 deletions doc/config.md
Expand Up @@ -27,8 +27,8 @@ allow-online-as-test: true
drop-test-temporary: true
# 语法检查小工具
only-syntax-check: false
sampling-data-factor: 100
sampling: true
sampling-statistic-target: 100
sampling: false
# 日志级别,[0:Emergency, 1:Alert, 2:Critical, 3:Error, 4:Warning, 5:Notice, 6:Informational, 7:Debug]
log-level: 7
log-output: ${your_log_dir}/soar.log
Expand Down Expand Up @@ -78,6 +78,10 @@ soar -h

### 命令行参数配置DSN

SOAR 最新版本已经使用`go-sql-driver`替代了`mymysql`,DSN将使用`go-sql-driver`格式并且保持向前兼容,请参考[go-sql-driver](https://github.com/go-sql-driver/mysql#dsn-data-source-name)文档。

**以下DSN格式不再推荐使用**

> 账号密码中如包含特殊符号(如:'@',':','/'等)可在配置文件中设置,存在特殊字符的情况不适合在命令行中使用。目前`soar`只支持 tcp 协议的 MySQL 数据库连接方式,如需要配置本机MySQL环境建议将`localhost`修改为'127.0.0.1',并检查对应的 'user'@'127.0.0.1' 账号是否存在。
```bash
Expand Down
4 changes: 2 additions & 2 deletions env/env.go
Expand Up @@ -99,9 +99,9 @@ func BuildEnv() (*VirtualEnv, *database.Connector) {
common.Config.OnlineDSN.Disable = true
}

// 判断测试环境与remote环境版本是否一致
// 判断测试环境与线上环境版本是否一致,要求测试环境版本不低于线上环境
if vEnvVersion < rEnvVersion {
common.Log.Warning("TestDSN MySQL version older than OnlineDSN(%d), TestDSN(%d) will not be used", vEnvVersion, rEnvVersion)
common.Log.Warning("TestDSN MySQL version older than OnlineDSN(%d), TestDSN(%d) will not be used", rEnvVersion, vEnvVersion)
common.Config.TestDSN.Disable = true
}

Expand Down

0 comments on commit 86afd23

Please sign in to comment.