Skip to content

Commit 6fe1344

Browse files
committed
go cron
1 parent bfa49d8 commit 6fe1344

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+23865
-0
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js linguist-language=GO
2+
*.css linguist-language=GO
3+
*.html linguist-language=GO

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
info.log
2+
go_cron

conf/app.conf

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
appname = go_cron
2+
httpport = 8089
3+
runmode = dev
4+
5+
##项目版本
6+
version=V1.1.2
7+
8+
# 允许同时运行的任务数
9+
jobs.pool = 100
10+
11+
# 站点名称
12+
site.name = 毫秒定时任务管理器
13+
14+
15+
# 数据库配置
16+
db.host = 127.0.0.1
17+
db.user = test
18+
db.password = test
19+
db.port = 3306
20+
db.name = cron_job
21+
db.prefix = pp_
22+
db.timezone = Asia/Shanghai
23+
24+
# 邮件服务器配置
25+
mail.queue_size = 100
26+
mail.from = [email protected]
27+
mail.host = smtp.example.com
28+
mail.port = 25
29+
mail.user = username
30+
mail.password = your password

controllers/common.go

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* @Author: yongze.chen
3+
* @Date: 2017-06-19 22:27:09
4+
* @Last Modified by: yongze.chen
5+
* @Last Modified time: 2017-06-22 11:15:33
6+
*/
7+
package controllers
8+
9+
import (
10+
"github.com/astaxie/beego"
11+
"go_cron/libs"
12+
"go_cron/models"
13+
"strconv"
14+
"strings"
15+
)
16+
17+
const (
18+
MSG_OK = 0
19+
MSG_ERR = -1
20+
)
21+
22+
type BaseController struct {
23+
beego.Controller
24+
controllerName string
25+
actionName string
26+
user *models.User
27+
userId int
28+
userName string
29+
pageSize int
30+
}
31+
32+
func (this *BaseController) Prepare() {
33+
this.pageSize = 20
34+
controllerName, actionName := this.GetControllerAndAction()
35+
this.controllerName = strings.ToLower(controllerName[0 : len(controllerName)-10])
36+
this.actionName = strings.ToLower(actionName)
37+
this.auth()
38+
39+
this.Data["version"] = beego.AppConfig.String("version")
40+
this.Data["siteName"] = beego.AppConfig.String("site.name")
41+
this.Data["curRoute"] = this.controllerName + "." + this.actionName
42+
this.Data["curController"] = this.controllerName
43+
this.Data["curAction"] = this.actionName
44+
this.Data["loginUserId"] = this.userId
45+
this.Data["loginUserName"] = this.userName
46+
this.Data["menuTag"] = this.controllerName
47+
}
48+
49+
//登录状态验证
50+
func (this *BaseController) auth() {
51+
arr := strings.Split(this.Ctx.GetCookie("auth"), "|")
52+
if len(arr) == 2 {
53+
idstr, password := arr[0], arr[1]
54+
userId, _ := strconv.Atoi(idstr)
55+
if userId > 0 {
56+
user, err := models.UserGetById(userId)
57+
if err == nil && password == libs.Md5([]byte(this.getClientIp()+"|"+user.Password+user.Salt)) {
58+
this.userId = user.Id
59+
this.userName = user.UserName
60+
this.user = user
61+
}
62+
}
63+
}
64+
65+
if this.userId == 0 && (this.controllerName != "main" ||
66+
(this.controllerName == "main" && this.actionName != "logout" && this.actionName != "login")) {
67+
this.redirect(beego.URLFor("MainController.Login"))
68+
}
69+
}
70+
71+
//渲染模版
72+
func (this *BaseController) display(tpl ...string) {
73+
var tplname string
74+
if len(tpl) > 0 {
75+
tplname = tpl[0] + ".html"
76+
} else {
77+
tplname = this.controllerName + "/" + this.actionName + ".html"
78+
}
79+
this.Layout = "public/layout.html"
80+
this.TplName = tplname
81+
}
82+
83+
// 重定向
84+
func (this *BaseController) redirect(url string) {
85+
this.Redirect(url, 302)
86+
this.StopRun()
87+
}
88+
89+
// 是否POST提交
90+
func (this *BaseController) isPost() bool {
91+
return this.Ctx.Request.Method == "POST"
92+
}
93+
94+
// 显示错误信息
95+
func (this *BaseController) showMsg(args ...string) {
96+
this.Data["message"] = args[0]
97+
redirect := this.Ctx.Request.Referer()
98+
if len(args) > 1 {
99+
redirect = args[1]
100+
}
101+
102+
this.Data["redirect"] = redirect
103+
this.Data["pageTitle"] = "系统提示"
104+
this.display("error/message")
105+
this.Render()
106+
this.StopRun()
107+
}
108+
109+
// 输出json
110+
func (this *BaseController) jsonResult(out interface{}) {
111+
this.Data["json"] = out
112+
this.ServeJSON()
113+
this.StopRun()
114+
}
115+
116+
func (this *BaseController) ajaxMsg(msg interface{}, msgno int) {
117+
out := make(map[string]interface{})
118+
out["status"] = msgno
119+
out["msg"] = msg
120+
121+
this.jsonResult(out)
122+
}
123+
124+
//获取用户IP地址
125+
func (this *BaseController) getClientIp() string {
126+
s := strings.Split(this.Ctx.Request.RemoteAddr, ":")
127+
return s[0]
128+
}

controllers/group.go

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* @Author: yongze.chen
3+
* @Date: 2017-06-21 10:27:40
4+
* @Last Modified by: yongze.chen
5+
* @Last Modified time: 2017-06-22 09:17:22
6+
*/
7+
8+
package controllers
9+
10+
import (
11+
"github.com/astaxie/beego"
12+
"go_cron/libs"
13+
"go_cron/models"
14+
"strconv"
15+
"strings"
16+
"time"
17+
)
18+
19+
type GroupController struct {
20+
BaseController
21+
}
22+
23+
func (this *GroupController) List() {
24+
page, _ := this.GetInt("page")
25+
if page < 1 {
26+
page = 1
27+
}
28+
29+
list, count := models.TaskGroupGetList(page, this.pageSize)
30+
31+
this.Data["pageTitle"] = "分组列表"
32+
this.Data["list"] = list
33+
this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.URLFor("GroupController.List"), true).ToString()
34+
this.display()
35+
}
36+
37+
func (this *GroupController) Add() {
38+
if this.isPost() {
39+
group := new(models.TaskGroup)
40+
group.GroupName = strings.TrimSpace(this.GetString("group_name"))
41+
group.UserId = this.userId
42+
group.Description = strings.TrimSpace(this.GetString("description"))
43+
group.CreateTime = time.Now().Unix()
44+
45+
_, err := models.TaskGroupAdd(group)
46+
if err != nil {
47+
this.ajaxMsg(err.Error(), MSG_ERR)
48+
}
49+
this.ajaxMsg("", MSG_OK)
50+
}
51+
52+
this.Data["pageTitle"] = "添加分组"
53+
this.display()
54+
}
55+
56+
func (this *GroupController) Edit() {
57+
id, _ := this.GetInt("id")
58+
59+
group, err := models.TaskGroupGetById(id)
60+
if err != nil {
61+
this.showMsg(err.Error())
62+
}
63+
64+
if this.isPost() {
65+
group.GroupName = strings.TrimSpace(this.GetString("group_name"))
66+
group.Description = strings.TrimSpace(this.GetString("description"))
67+
err := group.Update()
68+
if err != nil {
69+
this.ajaxMsg(err.Error(), MSG_ERR)
70+
}
71+
this.ajaxMsg("", MSG_OK)
72+
}
73+
74+
this.Data["pageTitle"] = "编辑分组"
75+
this.Data["group"] = group
76+
this.display()
77+
}
78+
79+
func (this *GroupController) Batch() {
80+
action := this.GetString("action")
81+
ids := this.GetStrings("ids")
82+
if len(ids) < 1 {
83+
this.ajaxMsg("请选择要操作的项目", MSG_ERR)
84+
}
85+
86+
for _, v := range ids {
87+
id, _ := strconv.Atoi(v)
88+
if id < 1 {
89+
continue
90+
}
91+
switch action {
92+
case "delete":
93+
models.TaskGroupDelById(id)
94+
models.TaskResetGroupId(id)
95+
}
96+
}
97+
98+
this.ajaxMsg("", MSG_OK)
99+
}

controllers/help.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* @Author: yongze.chen
3+
* @Date: 2017-06-21 10:29:55
4+
* @Last Modified by: yongze.chen
5+
* @Last Modified time: 2017-06-21 10:30:07
6+
*/
7+
8+
package controllers
9+
10+
type HelpController struct {
11+
BaseController
12+
}
13+
14+
func (this *HelpController) Index() {
15+
16+
this.Data["pageTitle"] = "使用帮助"
17+
this.display()
18+
}

0 commit comments

Comments
 (0)