diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index aabc1af..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go -go: - - 1.9.x -script: go test `go list ./... | grep -v vendor` - -notifications: - on_success: never - on_failure: always \ No newline at end of file diff --git a/README.md b/README.md index b22b816..f9ffaa6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # gocron - 定时任务管理系统 -[![Build Status](https://travis-ci.org/ouqiang/gocron.png)](https://travis-ci.org/ouqiang/gocron) [![Downloads](https://img.shields.io/github/downloads/ouqiang/gocron/total.svg)](https://github.com/ouqiang/gocron/releases) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/ouqiang/gocron/blob/master/LICENSE) [![Release](https://img.shields.io/github/release/ouqiang/gocron.svg?label=Release)](https://github.com/ouqiang/gocron/releases) diff --git a/cmd/gocron/gocron.go b/cmd/gocron/gocron.go index 5b84bcd..7d845e0 100644 --- a/cmd/gocron/gocron.go +++ b/cmd/gocron/gocron.go @@ -35,7 +35,10 @@ func main() { cliApp.Version, _ = goutil.FormatAppVersion(AppVersion, GitCommit, BuildDate) cliApp.Commands = getCommands() cliApp.Flags = append(cliApp.Flags, []cli.Flag{}...) - cliApp.Run(os.Args) + err := cliApp.Run(os.Args) + if err != nil { + logger.Fatal(err) + } } // getCommands diff --git a/internal/models/model.go b/internal/models/model.go index e7804e4..558fe22 100644 --- a/internal/models/model.go +++ b/internal/models/model.go @@ -132,8 +132,12 @@ func getDbEngineDSN(setting *setting.Setting) string { func keepDbAlived(engine *xorm.Engine) { t := time.Tick(dbPingInterval) + var err error for { <-t - engine.Ping() + err = engine.Ping() + if err != nil { + logger.Infof("database ping: %s", err) + } } } diff --git a/internal/models/user.go b/internal/models/user.go index 8289d80..da1b363 100644 --- a/internal/models/user.go +++ b/internal/models/user.go @@ -71,11 +71,8 @@ func (user *User) Match(username, password string) bool { return false } hashPassword := user.encryptPassword(password, user.Salt) - if hashPassword != user.Password { - return false - } - return true + return hashPassword == user.Password } // 获取用户详情 diff --git a/internal/modules/app/app.go b/internal/modules/app/app.go index a960c42..86aaa30 100644 --- a/internal/modules/app/app.go +++ b/internal/modules/app/app.go @@ -104,9 +104,7 @@ func GetCurrentVersionId() int { // ToNumberVersion 把字符串版本号a.b.c转换为整数版本号abc func ToNumberVersion(versionString string) int { - if strings.HasPrefix(versionString, "v") { - versionString = versionString[1:] - } + versionString = strings.TrimPrefix(versionString, "v") v := strings.Replace(versionString, ".", "", -1) if len(v) < 3 { v += "0" diff --git a/internal/modules/notify/mail.go b/internal/modules/notify/mail.go index 1b3a891..8a4bac2 100644 --- a/internal/modules/notify/mail.go +++ b/internal/modules/notify/mail.go @@ -54,7 +54,7 @@ func (mail *Mail) send(mailSetting models.Mail, toUsers []string, msg Message) { gomailMessage.SetHeader("To", toUsers...) gomailMessage.SetHeader("Subject", "gocron-定时任务通知") gomailMessage.SetBody("text/html", body) - mailer := gomail.NewPlainDialer(mailSetting.Host, mailSetting.Port, + mailer := gomail.NewDialer(mailSetting.Host, mailSetting.Port, mailSetting.User, mailSetting.Password) maxTimes := 3 i := 0 diff --git a/internal/modules/rpc/auth/Certification.go b/internal/modules/rpc/auth/Certification.go index 0bc3fbc..0e47add 100644 --- a/internal/modules/rpc/auth/Certification.go +++ b/internal/modules/rpc/auth/Certification.go @@ -22,11 +22,14 @@ func (c Certificate) GetTLSConfigForServer() (*tls.Config, error) { c.CertFile, c.KeyFile, ) + if err != nil { + return nil, err + } certPool := x509.NewCertPool() bs, err := ioutil.ReadFile(c.CAFile) if err != nil { - return nil, errors.New(fmt.Sprintf("failed to read client ca cert: %s", err)) + return nil, fmt.Errorf("failed to read client ca cert: %s", err) } ok := certPool.AppendCertsFromPEM(bs) @@ -48,11 +51,14 @@ func (c Certificate) GetTransportCredsForClient() (credentials.TransportCredenti c.CertFile, c.KeyFile, ) + if err != nil { + return nil, err + } certPool := x509.NewCertPool() bs, err := ioutil.ReadFile(c.CAFile) if err != nil { - return nil, errors.New(fmt.Sprintf("failed to read ca cert: %s", err)) + return nil, fmt.Errorf("failed to read ca cert: %s", err) } ok := certPool.AppendCertsFromPEM(bs) diff --git a/internal/modules/rpc/client/client.go b/internal/modules/rpc/client/client.go index c8e947c..b04e935 100644 --- a/internal/modules/rpc/client/client.go +++ b/internal/modules/rpc/client/client.go @@ -6,11 +6,12 @@ import ( "sync" "time" + "google.golang.org/grpc/status" + "github.com/ouqiang/gocron/internal/modules/logger" "github.com/ouqiang/gocron/internal/modules/rpc/grpcpool" pb "github.com/ouqiang/gocron/internal/modules/rpc/proto" "golang.org/x/net/context" - "google.golang.org/grpc" "google.golang.org/grpc/codes" ) @@ -70,7 +71,7 @@ func Exec(ip string, port int, taskReq *pb.TaskRequest) (string, error) { } func parseGRPCError(err error) (string, error) { - switch grpc.Code(err) { + switch status.Code(err) { case codes.Unavailable: return "", errUnavailable case codes.DeadlineExceeded: diff --git a/internal/routers/host/host.go b/internal/routers/host/host.go index b130ced..688e3f3 100644 --- a/internal/routers/host/host.go +++ b/internal/routers/host/host.go @@ -14,7 +14,7 @@ import ( "github.com/ouqiang/gocron/internal/modules/utils" "github.com/ouqiang/gocron/internal/routers/base" "github.com/ouqiang/gocron/internal/service" - "gopkg.in/macaron.v1" + macaron "gopkg.in/macaron.v1" ) const testConnectionCommand = "echo hello" @@ -25,6 +25,9 @@ func Index(ctx *macaron.Context) string { hostModel := new(models.Host) queryParams := parseQueryParams(ctx) total, err := hostModel.Total(queryParams) + if err != nil { + logger.Error(err) + } hosts, err := hostModel.List(queryParams) if err != nil { logger.Error(err) diff --git a/internal/routers/install/install.go b/internal/routers/install/install.go index 51177e3..22e0f8c 100644 --- a/internal/routers/install/install.go +++ b/internal/routers/install/install.go @@ -148,6 +148,9 @@ func testDbConnection(form InstallForm) error { s.Db.Database = form.DbName s.Db.Charset = "utf8" db, err := models.CreateTmpDb(&s) + if err != nil { + return err + } defer db.Close() err = db.Ping() if s.Db.Engine == "postgres" && err != nil { diff --git a/internal/routers/loginlog/login_log.go b/internal/routers/loginlog/login_log.go index 8c36f44..43266e7 100644 --- a/internal/routers/loginlog/login_log.go +++ b/internal/routers/loginlog/login_log.go @@ -5,7 +5,7 @@ import ( "github.com/ouqiang/gocron/internal/modules/logger" "github.com/ouqiang/gocron/internal/modules/utils" "github.com/ouqiang/gocron/internal/routers/base" - "gopkg.in/macaron.v1" + macaron "gopkg.in/macaron.v1" ) func Index(ctx *macaron.Context) string { @@ -13,6 +13,9 @@ func Index(ctx *macaron.Context) string { params := models.CommonMap{} base.ParsePageAndPageSize(ctx, params) total, err := loginLogModel.Total() + if err != nil { + logger.Error(err) + } loginLogs, err := loginLogModel.List(params) if err != nil { logger.Error(err) diff --git a/internal/service/task.go b/internal/service/task.go index ce6f5d9..c9d330d 100644 --- a/internal/service/task.go +++ b/internal/service/task.go @@ -1,7 +1,6 @@ package service import ( - "errors" "fmt" "net/http" "strconv" @@ -234,7 +233,7 @@ func (h *HTTPHandler) Run(taskModel models.Task, taskUniqueId int64) (result str } // 返回状态码非200,均为失败 if resp.StatusCode != http.StatusOK { - return resp.Body, errors.New(fmt.Sprintf("HTTP状态码非200-->%d", resp.StatusCode)) + return resp.Body, fmt.Errorf("HTTP状态码非200-->%d", resp.StatusCode) } return resp.Body, err diff --git a/makefile b/makefile index 1dfbe6f..abe3ec1 100644 --- a/makefile +++ b/makefile @@ -63,6 +63,9 @@ statik: go get github.com/rakyll/statik go generate ./... +.PHONY: lint + golangci-lint run + .PHONY: clean clean: rm bin/gocron