golangci-lint

pull/164/head v1.5.1
ouqiang 6 years ago
parent bf76393073
commit ec4a4c0855

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

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

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

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

@ -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
}
// 获取用户详情

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save