Some improve (#425)

* Some improve

1. Use bytes.Buffer.String or bytes.Buffer.Bytes
2. Use a single append to concatenate two slices
3. Poor file permissions used when creating file or using chmod
4. Using a deprecated function, variable, constant or field

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* improve

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2019-10-17 23:49:21 +08:00 committed by GitHub
parent 453c919510
commit a49bf91e75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View File

@ -95,7 +95,7 @@ func SetLogOut(log *logrus.Logger, outString string) error {
case "stderr":
log.Out = os.Stderr
default:
f, err := os.OpenFile(outString, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
f, err := os.OpenFile(outString, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return err

View File

@ -186,9 +186,7 @@ Retry:
// Device Group HTTP Response
if len(res.FailedRegistrationIDs) > 0 {
isError = true
for _, id := range res.FailedRegistrationIDs {
newTokens = append(newTokens, id)
}
newTokens = append(newTokens, res.FailedRegistrationIDs...)
LogPush(FailedPush, notification.To, req, errors.New("device group: partial success or all fails"))
if PushConf.Core.Sync {

View File

@ -133,7 +133,7 @@ func TestRootHandler(t *testing.T) {
r.GET("/").
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
data := []byte(r.Body.String())
data := r.Body.Bytes()
value, _ := jsonparser.GetString(data, "text")
@ -150,7 +150,7 @@ func TestAPIStatusGoHandler(t *testing.T) {
r.GET("/api/stat/go").
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
data := []byte(r.Body.String())
data := r.Body.Bytes()
value, _ := jsonparser.GetString(data, "go_version")
@ -169,7 +169,7 @@ func TestAPIStatusAppHandler(t *testing.T) {
r.GET("/api/stat/app").
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
data := []byte(r.Body.String())
data := r.Body.Bytes()
value, _ := jsonparser.GetString(data, "version")
@ -346,7 +346,7 @@ func TestVersionHandler(t *testing.T) {
r.GET("/version").
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code)
data := []byte(r.Body.String())
data := r.Body.Bytes()
value, _ := jsonparser.GetString(data, "version")