使用goimports格式化代码

develop
ouqiang 2018-01-30 19:26:04 +08:00
parent 4c940c2088
commit 94c9963e81
31 changed files with 137 additions and 112 deletions

View File

@ -63,9 +63,9 @@ fi
echo '开始编译调度器'
if [[ $OS = 'windows' ]];then
GOOS=$OS GOARCH=$ARCH go build -tags gocron -ldflags '-w'
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -tags gocron -ldflags '-w'
else
GOOS=$OS GOARCH=$ARCH go build -tags gocron -ldflags '-w'
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -tags gocron -ldflags '-w'
fi
if [[ $? != 0 ]];then

View File

@ -70,9 +70,9 @@ fi
echo '开始编译任务节点'
if [[ $OS = 'windows' ]];then
GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
else
GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
fi
if [[ $? != 0 ]];then

View File

@ -1,6 +1,10 @@
package cmd
import (
"os"
"os/signal"
"syscall"
"github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/app"
"github.com/ouqiang/gocron/modules/logger"
@ -9,9 +13,6 @@ import (
"github.com/ouqiang/gocron/service"
"github.com/urfave/cli"
"gopkg.in/macaron.v1"
"os"
"os/signal"
"syscall"
)
// web服务器默认端口

View File

@ -3,9 +3,10 @@ package models
import (
"errors"
"fmt"
"strconv"
"github.com/go-xorm/xorm"
"github.com/ouqiang/gocron/modules/logger"
"strconv"
)
type Migration struct{}
@ -187,8 +188,6 @@ func (migration *Migration) upgradeFor140(session *xorm.Session) error {
return err
}
logger.Info("已升级到v1.4\n")
return err

View File

@ -2,6 +2,9 @@ package models
import (
"fmt"
"strings"
"time"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
@ -9,8 +12,6 @@ import (
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/setting"
"gopkg.in/macaron.v1"
"strings"
"time"
)
type Status int8

View File

@ -2,9 +2,10 @@ package models
import (
"errors"
"github.com/go-xorm/xorm"
"strings"
"time"
"github.com/go-xorm/xorm"
)
type TaskProtocol int8
@ -31,8 +32,8 @@ const (
type TaskHTTPMethod int8
const (
TaskHTTPMethodGet TaskHTTPMethod = 1;
TaskHttpMethodPost TaskHTTPMethod = 2;
TaskHTTPMethodGet TaskHTTPMethod = 1
TaskHttpMethodPost TaskHTTPMethod = 2
)
// 任务

View File

@ -1,8 +1,9 @@
package models
import (
"github.com/go-xorm/xorm"
"time"
"github.com/go-xorm/xorm"
)
type TaskType int8

View File

@ -1,8 +1,9 @@
package models
import (
"github.com/ouqiang/gocron/modules/utils"
"time"
"github.com/ouqiang/gocron/modules/utils"
)
const PasswordSaltLength = 6
@ -78,7 +79,7 @@ func (user *User) Match(username, password string) bool {
}
// 获取用户详情
func (user *User) Find(id int) (error) {
func (user *User) Find(id int) error {
_, err := Db.Id(id).Get(user)
return err

View File

@ -3,13 +3,14 @@ package app
import (
"os"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/setting"
"github.com/ouqiang/gocron/modules/utils"
"fmt"
"io/ioutil"
"strconv"
"strings"
"fmt"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/setting"
"github.com/ouqiang/gocron/modules/utils"
)
var (

View File

@ -2,10 +2,11 @@ package logger
import (
"fmt"
"github.com/cihub/seelog"
"gopkg.in/macaron.v1"
"os"
"runtime"
"github.com/cihub/seelog"
"gopkg.in/macaron.v1"
)
// 日志库

View File

@ -1,13 +1,14 @@
package notify
import (
"strconv"
"strings"
"time"
"github.com/go-gomail/gomail"
"github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/utils"
"strconv"
"strings"
"time"
)
// @author qiang.ou<qingqianludao@gmail.com>

View File

@ -2,8 +2,9 @@ package notify
import (
"fmt"
"github.com/ouqiang/gocron/modules/logger"
"time"
"github.com/ouqiang/gocron/modules/logger"
)
type Message map[string]interface{}

View File

@ -4,13 +4,14 @@ package notify
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/httpclient"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/utils"
"strconv"
"strings"
"time"
)
type Slack struct{}

View File

@ -5,8 +5,9 @@ import (
"crypto/x509"
"errors"
"fmt"
"google.golang.org/grpc/credentials"
"io/ioutil"
"google.golang.org/grpc/credentials"
)
type Certificate struct {

View File

@ -3,14 +3,15 @@ package client
import (
"errors"
"fmt"
"sync"
"time"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/rpc/grpcpool"
pb "github.com/ouqiang/gocron/modules/rpc/proto"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"time"
"sync"
)
var (

View File

@ -2,13 +2,14 @@ package grpcpool
import (
"errors"
"strings"
"sync"
"time"
"github.com/ouqiang/gocron/modules/app"
"github.com/ouqiang/gocron/modules/rpc/auth"
"github.com/silenceper/pool"
"google.golang.org/grpc"
"strings"
"sync"
"time"
)
var (

View File

@ -1,6 +1,8 @@
package server
import (
"net"
"github.com/ouqiang/gocron/modules/rpc/auth"
pb "github.com/ouqiang/gocron/modules/rpc/proto"
"github.com/ouqiang/gocron/modules/utils"
@ -8,7 +10,6 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
"net"
)
type Server struct{}

View File

@ -2,6 +2,7 @@ package setting
import (
"errors"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/utils"
"gopkg.in/ini.v1"

View File

@ -2,6 +2,7 @@ package utils
import (
"encoding/json"
"github.com/ouqiang/gocron/modules/logger"
)

View File

@ -3,11 +3,12 @@ package utils
import (
"crypto/md5"
"encoding/hex"
"github.com/Tang-RoseChild/mahonia"
"math/rand"
"os"
"strings"
"time"
"github.com/Tang-RoseChild/mahonia"
)
// 生成长度为length的随机字符串

View File

@ -4,9 +4,10 @@ package utils
import (
"errors"
"golang.org/x/net/context"
"os/exec"
"syscall"
"golang.org/x/net/context"
)
type Result struct {

View File

@ -4,10 +4,11 @@ package utils
import (
"errors"
"golang.org/x/net/context"
"os/exec"
"strconv"
"syscall"
"golang.org/x/net/context"
)
type Result struct {

View File

@ -2,6 +2,10 @@ package host
import (
"fmt"
"html/template"
"strconv"
"strings"
"github.com/Unknwon/paginater"
"github.com/go-macaron/binding"
"github.com/ouqiang/gocron/models"
@ -13,9 +17,6 @@ import (
"github.com/ouqiang/gocron/routers/base"
"github.com/ouqiang/gocron/service"
"gopkg.in/macaron.v1"
"html/template"
"strconv"
"strings"
)
// Index 主机列表

View File

@ -2,6 +2,8 @@ package install
import (
"fmt"
"strconv"
"github.com/go-macaron/binding"
"github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/app"
@ -9,7 +11,6 @@ import (
"github.com/ouqiang/gocron/modules/utils"
"github.com/ouqiang/gocron/service"
"gopkg.in/macaron.v1"
"strconv"
)
// 系统安装

View File

@ -2,12 +2,13 @@ package loginlog
import (
"fmt"
"html/template"
"github.com/Unknwon/paginater"
"github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/routers/base"
"gopkg.in/macaron.v1"
"html/template"
)
func Index(ctx *macaron.Context) {

View File

@ -2,6 +2,7 @@ package manage
import (
"encoding/json"
"github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/utils"

View File

@ -1,6 +1,12 @@
package routers
import (
"html/template"
"net/http"
"strconv"
"strings"
"time"
"github.com/go-macaron/binding"
"github.com/go-macaron/cache"
"github.com/go-macaron/captcha"
@ -18,11 +24,6 @@ import (
"github.com/ouqiang/gocron/routers/tasklog"
"github.com/ouqiang/gocron/routers/user"
"gopkg.in/macaron.v1"
"html/template"
"strconv"
"strings"
"time"
"net/http"
)
// 静态文件目录
@ -226,7 +227,7 @@ func urlAuth(ctx *macaron.Context, sess session.Store) {
}
uri := strings.TrimSpace(ctx.Req.URL.Path)
uri = strings.TrimRight(uri, "/")
if (strings.HasPrefix(uri, "/api")) {
if strings.HasPrefix(uri, "/api") {
return
}
// 普通用户允许访问的URL地址

View File

@ -2,6 +2,10 @@ package task
import (
"fmt"
"html/template"
"strconv"
"strings"
"github.com/Unknwon/paginater"
"github.com/go-macaron/binding"
"github.com/jakecoffman/cron"
@ -11,9 +15,6 @@ import (
"github.com/ouqiang/gocron/routers/base"
"github.com/ouqiang/gocron/service"
"gopkg.in/macaron.v1"
"html/template"
"strconv"
"strings"
)
type TaskForm struct {

View File

@ -4,14 +4,15 @@ package tasklog
import (
"fmt"
"html/template"
"github.com/Unknwon/paginater"
"github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/utils"
"github.com/ouqiang/gocron/routers/base"
"gopkg.in/macaron.v1"
"html/template"
"github.com/ouqiang/gocron/service"
"gopkg.in/macaron.v1"
)
func Index(ctx *macaron.Context) {
@ -70,7 +71,7 @@ func Stop(ctx *macaron.Context) string {
}
return json.Success("已执行停止操作, 请等待任务退出", nil);
return json.Success("已执行停止操作, 请等待任务退出", nil)
}
// 删除N个月前的日志

View File

@ -1,6 +1,11 @@
package user
import (
"fmt"
"html/template"
"strings"
"github.com/Unknwon/paginater"
"github.com/go-macaron/captcha"
"github.com/go-macaron/session"
"github.com/ouqiang/gocron/models"
@ -8,10 +13,6 @@ import (
"github.com/ouqiang/gocron/modules/utils"
"github.com/ouqiang/gocron/routers/base"
"gopkg.in/macaron.v1"
"github.com/Unknwon/paginater"
"html/template"
"fmt"
"strings"
)
// @author qiang.ou<qingqianludao@gmail.com>
@ -139,7 +140,6 @@ func Store(ctx *macaron.Context, form UserForm) string {
}
}
return json.Success("保存成功", nil)
}

View File

@ -3,6 +3,12 @@ package service
import (
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"sync"
"time"
"github.com/jakecoffman/cron"
"github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/httpclient"
@ -10,11 +16,6 @@ import (
"github.com/ouqiang/gocron/modules/notify"
rpcClient "github.com/ouqiang/gocron/modules/rpc/client"
pb "github.com/ouqiang/gocron/modules/rpc/proto"
"strconv"
"strings"
"sync"
"time"
"net/http"
)
var (
@ -92,7 +93,6 @@ type TaskResult struct {
RetryTimes int8
}
// 初始化任务, 从数据库取出所有任务, 添加到定时任务并运行
func (task Task) Initialize() {
taskModel := new(models.Task)
@ -171,13 +171,13 @@ func (h *HTTPHandler) Run(taskModel models.Task, taskUniqueId int64) (result str
taskModel.Timeout = HttpExecTimeout
}
var resp httpclient.ResponseWrapper
if (taskModel.HttpMethod == models.TaskHTTPMethodGet) {
if taskModel.HttpMethod == models.TaskHTTPMethodGet {
resp = httpclient.Get(taskModel.Command, taskModel.Timeout)
} else {
urlFields := strings.Split(taskModel.Command, "?")
taskModel.Command = urlFields[0]
var params string
if (len(urlFields) >= 2) {
if len(urlFields) >= 2 {
params = urlFields[1]
}
resp = httpclient.PostParams(taskModel.Command, params, taskModel.Timeout)