Skip to content

Commit

Permalink
golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ouqiang committed Jun 2, 2019
1 parent bf76393 commit ec4a4c0
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 27 deletions.
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 4 additions & 1 deletion cmd/gocron/gocron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion internal/models/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
5 changes: 1 addition & 4 deletions internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

// 获取用户详情
Expand Down
4 changes: 1 addition & 3 deletions internal/modules/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/modules/notify/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions internal/modules/rpc/auth/Certification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions internal/modules/rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion internal/routers/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion internal/routers/loginlog/login_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ 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 {
loginLogModel := new(models.LoginLog)
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)
Expand Down
3 changes: 1 addition & 2 deletions internal/service/task.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package service

import (
"errors"
"fmt"
"net/http"
"strconv"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ statik:
go get github.com/rakyll/statik
go generate ./...

.PHONY: lint
golangci-lint run

.PHONY: clean
clean:
rm bin/gocron
Expand Down

0 comments on commit ec4a4c0

Please sign in to comment.