使用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 '开始编译调度器' echo '开始编译调度器'
if [[ $OS = 'windows' ]];then 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 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 fi
if [[ $? != 0 ]];then if [[ $? != 0 ]];then

View File

@ -70,9 +70,9 @@ fi
echo '开始编译任务节点' echo '开始编译任务节点'
if [[ $OS = 'windows' ]];then 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 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 fi
if [[ $? != 0 ]];then if [[ $? != 0 ]];then

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,9 @@
package models package models
import ( import (
"github.com/ouqiang/gocron/modules/utils"
"time" "time"
"github.com/ouqiang/gocron/modules/utils"
) )
const PasswordSaltLength = 6 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) _, err := Db.Id(id).Get(user)
return err return err

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,14 +3,15 @@ package client
import ( import (
"errors" "errors"
"fmt" "fmt"
"sync"
"time"
"github.com/ouqiang/gocron/modules/logger" "github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/rpc/grpcpool" "github.com/ouqiang/gocron/modules/rpc/grpcpool"
pb "github.com/ouqiang/gocron/modules/rpc/proto" pb "github.com/ouqiang/gocron/modules/rpc/proto"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"time"
"sync"
) )
var ( var (
@ -25,7 +26,7 @@ func generateTaskUniqueKey(ip string, port int, id int64) string {
return fmt.Sprintf("%s:%d:%d", ip, port, id) return fmt.Sprintf("%s:%d:%d", ip, port, id)
} }
func Stop(ip string, port int , id int64) { func Stop(ip string, port int, id int64) {
key := generateTaskUniqueKey(ip, port, id) key := generateTaskUniqueKey(ip, port, id)
cancel, ok := taskMap.Load(key) cancel, ok := taskMap.Load(key)
if !ok { if !ok {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,12 @@
package routers package routers
import ( import (
"html/template"
"net/http"
"strconv"
"strings"
"time"
"github.com/go-macaron/binding" "github.com/go-macaron/binding"
"github.com/go-macaron/cache" "github.com/go-macaron/cache"
"github.com/go-macaron/captcha" "github.com/go-macaron/captcha"
@ -18,11 +24,6 @@ import (
"github.com/ouqiang/gocron/routers/tasklog" "github.com/ouqiang/gocron/routers/tasklog"
"github.com/ouqiang/gocron/routers/user" "github.com/ouqiang/gocron/routers/user"
"gopkg.in/macaron.v1" "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.TrimSpace(ctx.Req.URL.Path)
uri = strings.TrimRight(uri, "/") uri = strings.TrimRight(uri, "/")
if (strings.HasPrefix(uri, "/api")) { if strings.HasPrefix(uri, "/api") {
return return
} }
// 普通用户允许访问的URL地址 // 普通用户允许访问的URL地址

View File

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

View File

@ -4,14 +4,15 @@ package tasklog
import ( import (
"fmt" "fmt"
"html/template"
"github.com/Unknwon/paginater" "github.com/Unknwon/paginater"
"github.com/ouqiang/gocron/models" "github.com/ouqiang/gocron/models"
"github.com/ouqiang/gocron/modules/logger" "github.com/ouqiang/gocron/modules/logger"
"github.com/ouqiang/gocron/modules/utils" "github.com/ouqiang/gocron/modules/utils"
"github.com/ouqiang/gocron/routers/base" "github.com/ouqiang/gocron/routers/base"
"gopkg.in/macaron.v1"
"html/template"
"github.com/ouqiang/gocron/service" "github.com/ouqiang/gocron/service"
"gopkg.in/macaron.v1"
) )
func Index(ctx *macaron.Context) { func Index(ctx *macaron.Context) {
@ -57,7 +58,7 @@ func Stop(ctx *macaron.Context) string {
task, err := taskModel.Detail(taskId) task, err := taskModel.Detail(taskId)
json := utils.JsonResponse{} json := utils.JsonResponse{}
if err != nil { if err != nil {
return json.CommonFailure("获取任务信息失败#" + err.Error(), err) return json.CommonFailure("获取任务信息失败#"+err.Error(), err)
} }
if task.Protocol != models.TaskRPC { if task.Protocol != models.TaskRPC {
return json.CommonFailure("仅支持SHELL任务手动停止") return json.CommonFailure("仅支持SHELL任务手动停止")
@ -70,7 +71,7 @@ func Stop(ctx *macaron.Context) string {
} }
return json.Success("已执行停止操作, 请等待任务退出", nil); return json.Success("已执行停止操作, 请等待任务退出", nil)
} }
// 删除N个月前的日志 // 删除N个月前的日志

View File

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

View File

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