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:
parent
453c919510
commit
a49bf91e75
|
@ -95,7 +95,7 @@ func SetLogOut(log *logrus.Logger, outString string) error {
|
||||||
case "stderr":
|
case "stderr":
|
||||||
log.Out = os.Stderr
|
log.Out = os.Stderr
|
||||||
default:
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -186,9 +186,7 @@ Retry:
|
||||||
// Device Group HTTP Response
|
// Device Group HTTP Response
|
||||||
if len(res.FailedRegistrationIDs) > 0 {
|
if len(res.FailedRegistrationIDs) > 0 {
|
||||||
isError = true
|
isError = true
|
||||||
for _, id := range res.FailedRegistrationIDs {
|
newTokens = append(newTokens, res.FailedRegistrationIDs...)
|
||||||
newTokens = append(newTokens, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
LogPush(FailedPush, notification.To, req, errors.New("device group: partial success or all fails"))
|
LogPush(FailedPush, notification.To, req, errors.New("device group: partial success or all fails"))
|
||||||
if PushConf.Core.Sync {
|
if PushConf.Core.Sync {
|
||||||
|
|
|
@ -133,7 +133,7 @@ func TestRootHandler(t *testing.T) {
|
||||||
|
|
||||||
r.GET("/").
|
r.GET("/").
|
||||||
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
||||||
data := []byte(r.Body.String())
|
data := r.Body.Bytes()
|
||||||
|
|
||||||
value, _ := jsonparser.GetString(data, "text")
|
value, _ := jsonparser.GetString(data, "text")
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ func TestAPIStatusGoHandler(t *testing.T) {
|
||||||
|
|
||||||
r.GET("/api/stat/go").
|
r.GET("/api/stat/go").
|
||||||
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
||||||
data := []byte(r.Body.String())
|
data := r.Body.Bytes()
|
||||||
|
|
||||||
value, _ := jsonparser.GetString(data, "go_version")
|
value, _ := jsonparser.GetString(data, "go_version")
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ func TestAPIStatusAppHandler(t *testing.T) {
|
||||||
|
|
||||||
r.GET("/api/stat/app").
|
r.GET("/api/stat/app").
|
||||||
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
||||||
data := []byte(r.Body.String())
|
data := r.Body.Bytes()
|
||||||
|
|
||||||
value, _ := jsonparser.GetString(data, "version")
|
value, _ := jsonparser.GetString(data, "version")
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ func TestVersionHandler(t *testing.T) {
|
||||||
r.GET("/version").
|
r.GET("/version").
|
||||||
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
||||||
assert.Equal(t, http.StatusOK, r.Code)
|
assert.Equal(t, http.StatusOK, r.Code)
|
||||||
data := []byte(r.Body.String())
|
data := r.Body.Bytes()
|
||||||
|
|
||||||
value, _ := jsonparser.GetString(data, "version")
|
value, _ := jsonparser.GetString(data, "version")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue