Skip to content

Commit 1e85e03

Browse files
committed
utils备注统一化, 删除多余的函数
1 parent 43eef67 commit 1e85e03

18 files changed

+312
-175
lines changed

server/utils/cmd_Task.go

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,49 @@ import (
1111
"sync"
1212
)
1313

14+
//@author: [songzhibin97](https://github.com/songzhibin97)
15+
//@interface_name: RunTask
16+
//@description: Task接口
17+
1418
type RunTask interface {
1519
AddTask()
1620
RunTask()
1721
}
1822

19-
// T: Task任务
23+
//@author: [songzhibin97](https://github.com/songzhibin97)
24+
//@struct_name: T
25+
//@description: Task任务
26+
2027
type T struct {
2128
sync.Mutex
2229

23-
// ch: 获取事件channel
30+
// 获取事件channel
2431
ch chan struct{}
2532

2633
closeChan chan struct{}
2734

2835
// 记录process对象
2936
p *os.Process
3037

31-
// f: 执行任务
38+
// 执行任务
3239
f func(chan struct{}) error
3340
}
3441

35-
// NewT: 实例化方法
42+
//@author: [songzhibin97](https://github.com/songzhibin97)
43+
//@function: NewT
44+
//@description: T的实例化方法
45+
//@return: *T
46+
3647
func NewT() *T {
3748
return newT(nil)
3849
}
50+
51+
//@author: [songzhibin97](https://github.com/songzhibin97)
52+
//@function: newT
53+
//@description:
54+
//@param: f func(chan struct{}) error
55+
//@return: *T
56+
3957
func newT(f func(chan struct{}) error) *T {
4058
t := &T{
4159
Mutex: sync.Mutex{},
@@ -49,6 +67,11 @@ func newT(f func(chan struct{}) error) *T {
4967
return t
5068
}
5169

70+
//@author: [songzhibin97](https://github.com/songzhibin97)
71+
//@object: *T
72+
//@function: AddTask
73+
//@description: 添加任务
74+
5275
func (t *T) AddTask() {
5376
if len(t.ch) == 1 {
5477
return
@@ -63,6 +86,11 @@ func (t *T) AddTask() {
6386
t.ch <- struct{}{}
6487
}
6588

89+
//@author: [songzhibin97](https://github.com/songzhibin97)
90+
//@object: *T
91+
//@function: RunTask
92+
//@description: 启动任务
93+
6694
func (t *T) RunTask() {
6795
fmt.Println("进入")
6896
// 这里做的make 是用于关闭上一个执行的任务
@@ -82,7 +110,13 @@ func (t *T) RunTask() {
82110

83111
}
84112

85-
// DefaultF: 默认的StartFunction
113+
//@author: [songzhibin97](https://github.com/songzhibin97)
114+
//@object: t *T
115+
//@function: DefaultF
116+
//@description: 默认的StartFunction
117+
//@param: ch chan struct{}
118+
//@return: error
119+
86120
func (t *T) DefaultF(ch chan struct{}) error {
87121
var buildCmd *exec.Cmd
88122
var cmd *exec.Cmd
@@ -127,7 +161,13 @@ func (t *T) DefaultF(ch chan struct{}) error {
127161
return err
128162
}
129163

130-
// echo: 封装回显
164+
//@author: [songzhibin97](https://github.com/songzhibin97)
165+
//@object: t *T
166+
//@function: echo
167+
//@description: 封装回显
168+
//@param: cmd *exec.Cmd, ctx context.Context
169+
//@return: error
170+
131171
func (t *T) echo(cmd *exec.Cmd, ctx context.Context) error {
132172
var stdoutBuf bytes.Buffer
133173
stdoutIn, _ := cmd.StdoutPipe()

server/utils/cmd_monitor.go

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,31 @@ import (
99
"path/filepath"
1010
)
1111

12-
// Watch: 监控对象
12+
//@author: [songzhibin97](https://github.com/songzhibin97)
13+
//@struct_name: Watch
14+
//@description: 监控对象
15+
1316
type Watch struct {
1417
*fsnotify.Watcher
1518
}
1619

20+
//@author: [songzhibin97](https://github.com/songzhibin97)
21+
//@function: NewWatch
22+
//@description: Watch的实例化方法
23+
//@return: *Watch
24+
1725
func NewWatch() *Watch {
1826
obj, _ := fsnotify.NewWatcher()
1927
return &Watch{obj}
2028
}
2129

22-
// Watch: 监控对象
30+
//@author: [songzhibin97](https://github.com/songzhibin97)
31+
//@object: w *Watch
32+
//@function: Watch
33+
//@description: 监控对象
34+
//@param: path string, t *T
35+
//@return: error
36+
2337
func (w *Watch) Watch(path string, t *T) error {
2438
// 先转化为绝对路径
2539
path, err := filepath.Abs(path)
@@ -81,7 +95,13 @@ func (w *Watch) Watch(path string, t *T) error {
8195

8296
}
8397

84-
// watchDir: 处理监控目录
98+
//@author: [songzhibin97](https://github.com/songzhibin97)
99+
//@object: w *Watch
100+
//@function: watchDir
101+
//@description: 处理监控目录
102+
//@param: path string
103+
//@return: error
104+
85105
func (w *Watch) watchDir(path string) error {
86106
// 先将自己添加到监控
87107
err := w.Add(path)
@@ -113,7 +133,13 @@ func (w *Watch) watchDir(path string) error {
113133
return err
114134
}
115135

116-
// watchDir: 处理监控单文件
136+
//@author: [songzhibin97](https://github.com/songzhibin97)
137+
//@object: w *Watch
138+
//@function: watchDir
139+
//@description: 处理监控单文件
140+
//@param: path string
141+
//@return: error
142+
117143
func (w *Watch) watchFile(path string) error {
118144
var err error
119145
if chickPower(path) {
@@ -122,13 +148,24 @@ func (w *Watch) watchFile(path string) error {
122148
return err
123149
}
124150

125-
// chickPower: 判断是否在可控范围内
151+
//@author: [songzhibin97](https://github.com/songzhibin97)
152+
//@function: chickPower
153+
//@description: 判断是否在可控范围内
154+
//@param: path string
155+
//@return: error
156+
126157
func chickPower(name string) bool {
127158
name = filepath.Ext(name)
128159
return name == ".go" || name == ".yaml"
129160
}
130161

131-
// addTask: 偏函数 简化发送任务
162+
//@author: [songzhibin97](https://github.com/songzhibin97)
163+
//@object: w *Watch
164+
//@function: addTask
165+
//@description: 偏函数 简化发送任务
166+
//@param: path string
167+
//@return: error
168+
132169
func (w *Watch) addTask(t *T, name string) {
133170
if chickPower(name) {
134171
fmt.Println("Add Task->>>>>>")

server/utils/directory.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"os"
77
)
88

9-
// @title PathExists
10-
// @description 文件目录是否存在
11-
// @auth (2020/04/05 20:22)
12-
// @param path string
13-
// @return err error
9+
//@author: [piexlmax](https://github.com/piexlmax)
10+
//@function: PathExists
11+
//@description: 文件目录是否存在
12+
//@param: path string
13+
//@return: bool, error
1414

1515
func PathExists(path string) (bool, error) {
1616
_, err := os.Stat(path)
@@ -23,11 +23,11 @@ func PathExists(path string) (bool, error) {
2323
return false, err
2424
}
2525

26-
// @title createDir
27-
// @description 批量创建文件夹
28-
// @auth (2020/04/05 20:22)
29-
// @param dirs string
30-
// @return err error
26+
//@author: [piexlmax](https://github.com/piexlmax)
27+
//@function: CreateDir
28+
//@description: 批量创建文件夹
29+
//@param: dirs ...string
30+
//@return: err error
3131

3232
func CreateDir(dirs ...string) (err error) {
3333
for _, v := range dirs {

server/utils/email.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ import (
1111
"github.com/jordan-wright/email"
1212
)
1313

14+
//@author: [maplepie](https://github.com/maplepie)
15+
//@function: Email
16+
//@description: Email发送方法
17+
//@param: subject string, body string
18+
//@return: error
19+
1420
func Email(subject string, body string) error {
1521
to := strings.Split(global.GVA_CONFIG.Email.To, ",")
1622
return send(to, subject, body)
1723
}
1824

19-
// ErrorToEmail Error 发送邮件
25+
//@author: [SliverHorn](https://github.com/SliverHorn)
26+
//@function: ErrorToEmail
27+
//@description: 给email中间件错误发送邮件到指定邮箱
28+
//@param: subject string, body string
29+
//@return: error
30+
2031
func ErrorToEmail(subject string, body string) error {
2132
to := strings.Split(global.GVA_CONFIG.Email.To, ",")
2233
if to[len(to)-1] == "" { // 判断切片的最后一个元素是否为空,为空则移除
@@ -25,11 +36,23 @@ func ErrorToEmail(subject string, body string) error {
2536
return send(to, subject, body)
2637
}
2738

39+
//@author: [maplepie](https://github.com/maplepie)
40+
//@function: EmailTest
41+
//@description: Email测试方法
42+
//@param: subject string, body string
43+
//@return: error
44+
2845
func EmailTest(subject string, body string) error {
2946
to := []string{global.GVA_CONFIG.Email.From}
3047
return send(to, subject, body)
3148
}
3249

50+
//@author: [maplepie](https://github.com/maplepie)
51+
//@function: send
52+
//@description: Email发送方法
53+
//@param: subject string, body string
54+
//@return: error
55+
3356
func send(to []string, subject string, body string) error {
3457
from := global.GVA_CONFIG.Email.From
3558
nickname := global.GVA_CONFIG.Email.Nickname

server/utils/file_operations.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import (
55
"path/filepath"
66
)
77

8-
// FileMove: 文件移动供外部调用
9-
// src: 源位置 绝对路径相对路径都可以
10-
// dst: 目标位置 绝对路径相对路径都可以 dst 必须为文件夹
8+
//@author: [songzhibin97](https://github.com/songzhibin97)
9+
//@function: FileMove
10+
//@description: 文件移动供外部调用
11+
//@param: src string, dst string(src: 源位置,绝对路径or相对路径, dst: 目标位置,绝对路径or相对路径,必须为文件夹)
12+
//@return: err error
13+
1114
func FileMove(src string, dst string) (err error) {
1215
if dst == "" {
1316
return nil

server/utils/fmt_plus.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import (
66
"strings"
77
)
88

9-
// 利用反射将结构体转化为map
9+
//@author: [piexlmax](https://github.com/piexlmax)
10+
//@function: StructToMap
11+
//@description: 利用反射将结构体转化为map
12+
//@param: obj interface{}
13+
//@return: map[string]interface{}
14+
1015
func StructToMap(obj interface{}) map[string]interface{} {
1116
obj1 := reflect.TypeOf(obj)
1217
obj2 := reflect.ValueOf(obj)
@@ -18,7 +23,12 @@ func StructToMap(obj interface{}) map[string]interface{} {
1823
return data
1924
}
2025

21-
//将数组格式化为字符串
26+
//@author: [piexlmax](https://github.com/piexlmax)
27+
//@function: ArrayToString
28+
//@description: 将数组格式化为字符串
29+
//@param: array []interface{}
30+
//@return: string
31+
2232
func ArrayToString(array []interface{}) string {
2333
return strings.Replace(strings.Trim(fmt.Sprint(array), "[]"), " ", ",", -1)
2434
}

server/utils/md5.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import (
55
"encoding/hex"
66
)
77

8+
//@author: [piexlmax](https://github.com/piexlmax)
9+
//@function: MD5V
10+
//@description: md5加密
11+
//@param: str []byte
12+
//@return: string
13+
814
func MD5V(str []byte) string {
915
h := md5.New()
1016
h.Write(str)

server/utils/rotatelogs_unix.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import (
1111
"time"
1212
)
1313

14-
// GetWriteSyncer zap logger中加入file-rotatelogs
14+
//@author: [SliverHorn](https://github.com/SliverHorn)
15+
//@function: GetWriteSyncer
16+
//@description: zap logger中加入file-rotatelogs
17+
//@return: zapcore.WriteSyncer, error
18+
1519
func GetWriteSyncer() (zapcore.WriteSyncer, error) {
1620
fileWriter, err := zaprotatelogs.New(
1721
path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"),

server/utils/rotatelogs_windows.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import (
99
"time"
1010
)
1111

12-
// GetWriteSyncer zap logger中加入file-rotatelogs
12+
//@author: [SliverHorn](https://github.com/SliverHorn)
13+
//@function: GetWriteSyncer
14+
//@description: zap logger中加入file-rotatelogs
15+
//@return: zapcore.WriteSyncer, error
16+
1317
func GetWriteSyncer() (zapcore.WriteSyncer, error) {
1418
fileWriter, err := zaprotatelogs.New(
1519
path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"),

0 commit comments

Comments
 (0)