golangci-lint

pull/164/head v1.5.1
ouqiang 2019-06-02 14:27:04 +08:00
parent bf76393073
commit ec4a4c0855
14 changed files with 38 additions and 27 deletions

View File

@ -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

View File

@ -1,5 +1,4 @@
# gocron - 定时任务管理系统 # 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) [![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) [![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) [![Release](https://img.shields.io/github/release/ouqiang/gocron.svg?label=Release)](https://github.com/ouqiang/gocron/releases)

View File

@ -35,7 +35,10 @@ func main() {
cliApp.Version, _ = goutil.FormatAppVersion(AppVersion, GitCommit, BuildDate) cliApp.Version, _ = goutil.FormatAppVersion(AppVersion, GitCommit, BuildDate)
cliApp.Commands = getCommands() cliApp.Commands = getCommands()
cliApp.Flags = append(cliApp.Flags, []cli.Flag{}...) cliApp.Flags = append(cliApp.Flags, []cli.Flag{}...)
cliApp.Run(os.Args) err := cliApp.Run(os.Args)
if err != nil {
logger.Fatal(err)
}
} }
// getCommands // getCommands

View File

@ -132,8 +132,12 @@ func getDbEngineDSN(setting *setting.Setting) string {
func keepDbAlived(engine *xorm.Engine) { func keepDbAlived(engine *xorm.Engine) {
t := time.Tick(dbPingInterval) t := time.Tick(dbPingInterval)
var err error
for { for {
<-t <-t
engine.Ping() err = engine.Ping()
if err != nil {
logger.Infof("database ping: %s", err)
}
} }
} }

View File

@ -71,11 +71,8 @@ func (user *User) Match(username, password string) bool {
return false return false
} }
hashPassword := user.encryptPassword(password, user.Salt) hashPassword := user.encryptPassword(password, user.Salt)
if hashPassword != user.Password {
return false
}
return true return hashPassword == user.Password
} }
// 获取用户详情 // 获取用户详情

View File

@ -104,9 +104,7 @@ func GetCurrentVersionId() int {
// ToNumberVersion 把字符串版本号a.b.c转换为整数版本号abc // ToNumberVersion 把字符串版本号a.b.c转换为整数版本号abc
func ToNumberVersion(versionString string) int { func ToNumberVersion(versionString string) int {
if strings.HasPrefix(versionString, "v") { versionString = strings.TrimPrefix(versionString, "v")
versionString = versionString[1:]
}
v := strings.Replace(versionString, ".", "", -1) v := strings.Replace(versionString, ".", "", -1)
if len(v) < 3 { if len(v) < 3 {
v += "0" v += "0"

View File

@ -54,7 +54,7 @@ func (mail *Mail) send(mailSetting models.Mail, toUsers []string, msg Message) {
gomailMessage.SetHeader("To", toUsers...) gomailMessage.SetHeader("To", toUsers...)
gomailMessage.SetHeader("Subject", "gocron-定时任务通知") gomailMessage.SetHeader("Subject", "gocron-定时任务通知")
gomailMessage.SetBody("text/html", body) gomailMessage.SetBody("text/html", body)
mailer := gomail.NewPlainDialer(mailSetting.Host, mailSetting.Port, mailer := gomail.NewDialer(mailSetting.Host, mailSetting.Port,
mailSetting.User, mailSetting.Password) mailSetting.User, mailSetting.Password)
maxTimes := 3 maxTimes := 3
i := 0 i := 0

View File

@ -22,11 +22,14 @@ func (c Certificate) GetTLSConfigForServer() (*tls.Config, error) {
c.CertFile, c.CertFile,
c.KeyFile, c.KeyFile,
) )
if err != nil {
return nil, err
}
certPool := x509.NewCertPool() certPool := x509.NewCertPool()
bs, err := ioutil.ReadFile(c.CAFile) bs, err := ioutil.ReadFile(c.CAFile)
if err != nil { 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) ok := certPool.AppendCertsFromPEM(bs)
@ -48,11 +51,14 @@ func (c Certificate) GetTransportCredsForClient() (credentials.TransportCredenti
c.CertFile, c.CertFile,
c.KeyFile, c.KeyFile,
) )
if err != nil {
return nil, err
}
certPool := x509.NewCertPool() certPool := x509.NewCertPool()
bs, err := ioutil.ReadFile(c.CAFile) bs, err := ioutil.ReadFile(c.CAFile)
if err != nil { 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) ok := certPool.AppendCertsFromPEM(bs)

View File

@ -6,11 +6,12 @@ import (
"sync" "sync"
"time" "time"
"google.golang.org/grpc/status"
"github.com/ouqiang/gocron/internal/modules/logger" "github.com/ouqiang/gocron/internal/modules/logger"
"github.com/ouqiang/gocron/internal/modules/rpc/grpcpool" "github.com/ouqiang/gocron/internal/modules/rpc/grpcpool"
pb "github.com/ouqiang/gocron/internal/modules/rpc/proto" pb "github.com/ouqiang/gocron/internal/modules/rpc/proto"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes" "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) { func parseGRPCError(err error) (string, error) {
switch grpc.Code(err) { switch status.Code(err) {
case codes.Unavailable: case codes.Unavailable:
return "", errUnavailable return "", errUnavailable
case codes.DeadlineExceeded: case codes.DeadlineExceeded:

View File

@ -14,7 +14,7 @@ import (
"github.com/ouqiang/gocron/internal/modules/utils" "github.com/ouqiang/gocron/internal/modules/utils"
"github.com/ouqiang/gocron/internal/routers/base" "github.com/ouqiang/gocron/internal/routers/base"
"github.com/ouqiang/gocron/internal/service" "github.com/ouqiang/gocron/internal/service"
"gopkg.in/macaron.v1" macaron "gopkg.in/macaron.v1"
) )
const testConnectionCommand = "echo hello" const testConnectionCommand = "echo hello"
@ -25,6 +25,9 @@ func Index(ctx *macaron.Context) string {
hostModel := new(models.Host) hostModel := new(models.Host)
queryParams := parseQueryParams(ctx) queryParams := parseQueryParams(ctx)
total, err := hostModel.Total(queryParams) total, err := hostModel.Total(queryParams)
if err != nil {
logger.Error(err)
}
hosts, err := hostModel.List(queryParams) hosts, err := hostModel.List(queryParams)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)

View File

@ -148,6 +148,9 @@ func testDbConnection(form InstallForm) error {
s.Db.Database = form.DbName s.Db.Database = form.DbName
s.Db.Charset = "utf8" s.Db.Charset = "utf8"
db, err := models.CreateTmpDb(&s) db, err := models.CreateTmpDb(&s)
if err != nil {
return err
}
defer db.Close() defer db.Close()
err = db.Ping() err = db.Ping()
if s.Db.Engine == "postgres" && err != nil { if s.Db.Engine == "postgres" && err != nil {

View File

@ -5,7 +5,7 @@ import (
"github.com/ouqiang/gocron/internal/modules/logger" "github.com/ouqiang/gocron/internal/modules/logger"
"github.com/ouqiang/gocron/internal/modules/utils" "github.com/ouqiang/gocron/internal/modules/utils"
"github.com/ouqiang/gocron/internal/routers/base" "github.com/ouqiang/gocron/internal/routers/base"
"gopkg.in/macaron.v1" macaron "gopkg.in/macaron.v1"
) )
func Index(ctx *macaron.Context) string { func Index(ctx *macaron.Context) string {
@ -13,6 +13,9 @@ func Index(ctx *macaron.Context) string {
params := models.CommonMap{} params := models.CommonMap{}
base.ParsePageAndPageSize(ctx, params) base.ParsePageAndPageSize(ctx, params)
total, err := loginLogModel.Total() total, err := loginLogModel.Total()
if err != nil {
logger.Error(err)
}
loginLogs, err := loginLogModel.List(params) loginLogs, err := loginLogModel.List(params)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)

View File

@ -1,7 +1,6 @@
package service package service
import ( import (
"errors"
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
@ -234,7 +233,7 @@ func (h *HTTPHandler) Run(taskModel models.Task, taskUniqueId int64) (result str
} }
// 返回状态码非200均为失败 // 返回状态码非200均为失败
if resp.StatusCode != http.StatusOK { 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 return resp.Body, err

View File

@ -63,6 +63,9 @@ statik:
go get github.com/rakyll/statik go get github.com/rakyll/statik
go generate ./... go generate ./...
.PHONY: lint
golangci-lint run
.PHONY: clean .PHONY: clean
clean: clean:
rm bin/gocron rm bin/gocron