-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e622468
commit 1b8bf48
Showing
5 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# cock | ||
# cock 程序唤起/任务调度 | ||
|
||
一个兼备程序唤起和任务调度程序 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"github.com/leancodebox/cock/jobmanager" | ||
"github.com/leancodebox/cock/resource" | ||
"log/slog" | ||
"os" | ||
"os/signal" | ||
) | ||
|
||
func init() { | ||
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, nil))) | ||
} | ||
|
||
func main() { | ||
if _, err := os.Stat("jobConfig.json"); os.IsNotExist(err) { | ||
fmt.Println("当前目录下不存在jobConfig.json文件") | ||
|
||
// 询问是否生成该文件 | ||
fmt.Print("是否生成jobConfig.json文件?(yes/no): ") | ||
var answer string | ||
_, err := fmt.Scanln(&answer) | ||
if err != nil { | ||
fmt.Println("无法读取输入,错误:", err) | ||
return | ||
} | ||
|
||
if answer == "yes" { | ||
err = os.WriteFile("jobConfig.json", resource.GetJobConfigDefault(), 0644) | ||
if err != nil { | ||
fmt.Println("无法写入文件,错误:", err) | ||
return | ||
} | ||
fmt.Println("jobConfig.json文件已生成并写入内容。请调整配置后再次启动") | ||
} else { | ||
fmt.Println("请补充 jobConfig.json 后再次启动程序") | ||
} | ||
return | ||
} | ||
fileData, err := os.ReadFile("jobConfig.json") | ||
if err != nil { | ||
slog.Error(err.Error()) | ||
return | ||
} | ||
|
||
jobmanager.Reg(fileData) | ||
quit := make(chan os.Signal) | ||
signal.Notify(quit, os.Interrupt) | ||
<-quit | ||
slog.Info("bye~~👋👋") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package resource | ||
|
||
import ( | ||
_ "embed" | ||
) | ||
|
||
//go:embed jobConfig.example.json | ||
var jobConfigDefault []byte | ||
|
||
func GetJobConfigDefault() []byte { | ||
return jobConfigDefault | ||
} |