Skip to content

Commit 326bfbc

Browse files
committed
v0.8.2
- 支持插件Debug模式 - 插件调试工具支持Debug模式 - goreleaser配置增加插件工具编译
1 parent ebcebd9 commit 326bfbc

File tree

16 files changed

+315
-175
lines changed

16 files changed

+315
-175
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ main
2828
.idea/
2929
modules/proxy/
3030
note_*.*
31-
.vscode/
31+
.vscode/
32+
dist/

.goreleaser.yml

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
before:
44
hooks: []
55
builds:
6-
- env:
6+
- id: AnimeGo
7+
main: cmd/animego/main.go
8+
binary: AnimeGo
9+
env:
710
- CGO_ENABLED=0
811
flags:
912
- -trimpath
@@ -21,22 +24,56 @@ builds:
2124
- mips64
2225
- mips64le
2326
goarm:
24-
- 5
2527
- 6
2628
- 7
2729
gomips:
2830
- hardfloat
2931
- softfloat
32+
ignore:
33+
- goos: windows
34+
goarch: arm
35+
goarm: 6
36+
- goos: windows
37+
goarch: arm
38+
goarm: 7
3039
ldflags:
31-
- -s -w -X main.version={{.Tag}} -X main.buildTime={{.Date}}
32-
main: cmd/animego/main.go
40+
- -s -w -X "github.com/wetor/AnimeGo/cmd/common.version={{.Tag}}" -X "github.com/wetor/AnimeGo/cmd/common.buildTime={{.Date}}"
41+
42+
- id: AnimeGo-plugin
43+
main: cmd/plugin/main.go
44+
binary: AnimeGo-plugin
45+
env:
46+
- CGO_ENABLED=0
47+
flags:
48+
- -trimpath
49+
goos:
50+
- linux
51+
- windows
52+
- darwin
53+
goarch:
54+
- 386
55+
- amd64
56+
- arm64
57+
ldflags:
58+
- -s -w -X "github.com/wetor/AnimeGo/cmd/common.version={{.Tag}}" -X "github.com/wetor/AnimeGo/cmd/common.buildTime={{.Date}}"
3359
archives:
34-
- replacements:
35-
darwin: Darwin
36-
linux: Linux
37-
windows: Windows
38-
386: i386
39-
amd64: x86_64
60+
- name_template: >-
61+
{{- .Binary }}_
62+
{{- .Tag }}_
63+
{{- title .Os }}_
64+
{{- if eq .Arch "amd64" }}x86_64
65+
{{- else if eq .Arch "386" }}i386
66+
{{- else }}{{ .Arch }}{{ end }}
67+
{{- if .Arm }}v{{ .Arm }}{{ end }}
68+
{{- if .Mips }}_{{ .Mips }}{{ end }}
69+
allow_different_binary_count: true
70+
builds:
71+
- AnimeGo
72+
- AnimeGo-plugin
73+
format_overrides:
74+
- goos: windows
75+
format: zip
76+
4077
checksum:
4178
name_template: 'checksums.txt'
4279
snapshot:

assets/plugin/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,28 @@ log.errorf(format, ...)
165165
`vars`将会追加并覆盖 `builtin_mikan_rss.py` 中的全局变量`__cron__`,`__name__`,`__url__`变量
166166
其他字段参考配置文件中的注释
167167

168+
## 通用的内置变量和函数
169+
所有被AnimeGo载入的插件,都将拥有以下变量或方法
170+
### \_\_debug\_\_
171+
全局变量`__debug__`,bool类型,当前是否为debug模式
172+
173+
### \_\_plugin_name\_\_
174+
全局变量`__plugin_name__`,插件文件名,不含扩展名
175+
176+
### \_\_plugin_dir\_\_
177+
全局变量`__plugin_dir__`,插件所在目录,绝对路径
178+
179+
### \_\_animego_version\_\_
180+
全局变量`__animego_version__`,AnimeGo版本号,`vx.x.x`格式,如`v1.0.0`
181+
182+
### \_get_config()
183+
内置函数`_get_config`,获取插件配置
184+
`_get_config() -> dict`
185+
读取插件所在目录下,同名的**yaml**或**json**文件并解析为dict。优先读取yaml,其次json,若都不存在返回空
186+
187+
```python
188+
conf = _get_config()
189+
```
168190

169191
## Feed订阅插件
170192
解析订阅内容

cmd/animego/main.go

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import (
66
"fmt"
77
"log"
88
"os"
9-
"os/signal"
109
"sync"
11-
"syscall"
1210
"time"
1311

1412
"github.com/wetor/AnimeGo/assets"
13+
"github.com/wetor/AnimeGo/cmd/common"
1514
"github.com/wetor/AnimeGo/configs"
1615
_ "github.com/wetor/AnimeGo/docs"
1716
"github.com/wetor/AnimeGo/internal/animego/anidata"
@@ -45,11 +44,6 @@ const (
4544
DefaultConfigFile = "data/animego.yaml"
4645
)
4746

48-
var (
49-
version = "dev"
50-
buildTime = "dev"
51-
)
52-
5347
var (
5448
ctx, cancel = context.WithCancel(context.Background())
5549
configFile string
@@ -60,36 +54,25 @@ var (
6054
BangumiCacheMutex sync.Mutex
6155
)
6256

63-
func init() {
64-
var err error
65-
err = os.Setenv("ANIMEGO_VERSION", fmt.Sprintf("%s-%s", version, buildTime))
66-
if err != nil {
67-
panic(err)
68-
}
69-
}
70-
7157
func main() {
72-
printInfo()
58+
common.PrintInfo()
7359

7460
flag.StringVar(&configFile, "config", DefaultConfigFile, "配置文件路径;配置文件中的相对路径均是相对与程序的位置")
7561
flag.BoolVar(&debug, "debug", false, "Debug模式,将会显示更多的日志")
7662
flag.BoolVar(&webapi, "web", true, "启用Web API,默认启用")
7763
flag.Parse()
7864

79-
sigs := make(chan os.Signal, 1)
80-
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
65+
common.RegisterExit(doExit)
66+
Main()
67+
}
68+
69+
func doExit() {
70+
pkgLog.Infof("正在退出...")
71+
cancel()
8172
go func() {
82-
for s := range sigs {
83-
switch s {
84-
case syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT:
85-
pkgLog.Infof("收到退出信号: %v", s)
86-
doExit()
87-
default:
88-
pkgLog.Infof("收到其他信号: %v", s)
89-
}
90-
}
73+
time.Sleep(5 * time.Second)
74+
os.Exit(0)
9175
}()
92-
Main(ctx)
9376
}
9477

9578
func InitDefaultConfig() {
@@ -126,30 +109,7 @@ func InitDefaultAssets(dataPath string, skip bool) {
126109
assets.WritePlugins(assets.Dir, xpath.Join(dataPath, assets.Dir), skip)
127110
}
128111

129-
func doExit() {
130-
pkgLog.Infof("正在退出...")
131-
cancel()
132-
go func() {
133-
time.Sleep(5 * time.Second)
134-
os.Exit(0)
135-
}()
136-
}
137-
138-
func printInfo() {
139-
fmt.Println(`--------------------------------------------------
140-
___ _ ______
141-
/ | ____ (_)____ ___ ___ / ____/____
142-
/ /| | / __ \ / // __ \__ \ / _ \ / / __ / __ \
143-
/ ___ | / / / // // / / / / // __// /_/ // /_/ /
144-
/_/ |_|/_/ /_//_//_/ /_/ /_/ \___/ \____/ \____/
145-
`)
146-
fmt.Printf("AnimeGo %s\n", os.Getenv("ANIMEGO_VERSION"))
147-
fmt.Printf("AnimeGo config v%s\n", configs.ConfigVersion)
148-
fmt.Printf("%s\n", constant.AnimeGoGithub)
149-
fmt.Println("--------------------------------------------------")
150-
}
151-
152-
func Main(ctx context.Context) {
112+
func Main() {
153113
configFile = xpath.Abs(configFile)
154114
// 初始化默认配置、升级配置
155115
InitDefaultConfig()
@@ -184,7 +144,8 @@ func Main(ctx context.Context) {
184144

185145
// 初始化插件-gpython
186146
plugin.Init(&plugin.Options{
187-
Path: constant.PluginPath,
147+
Path: constant.PluginPath,
148+
Debug: debug,
188149
})
189150
// 载入AnimeGo数据库(缓存)
190151
bolt := cache.NewBolt()

cmd/common/common.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package common
2+
3+
import (
4+
"fmt"
5+
"github.com/wetor/AnimeGo/configs"
6+
"github.com/wetor/AnimeGo/internal/constant"
7+
"os"
8+
"os/signal"
9+
"syscall"
10+
11+
pkgLog "github.com/wetor/AnimeGo/pkg/log"
12+
)
13+
14+
var (
15+
version = "dev"
16+
buildTime = "dev"
17+
)
18+
19+
func init() {
20+
err := os.Setenv("ANIMEGO_VERSION", fmt.Sprintf("%s-%s", version, buildTime))
21+
if err != nil {
22+
panic(err)
23+
}
24+
}
25+
26+
func PrintInfo() {
27+
fmt.Println(`--------------------------------------------------
28+
___ _ ______
29+
/ | ____ (_)____ ___ ___ / ____/____
30+
/ /| | / __ \ / // __ \__ \ / _ \ / / __ / __ \
31+
/ ___ | / / / // // / / / / // __// /_/ // /_/ /
32+
/_/ |_|/_/ /_//_//_/ /_/ /_/ \___/ \____/ \____/
33+
`)
34+
fmt.Printf("AnimeGo %s\n", os.Getenv("ANIMEGO_VERSION"))
35+
fmt.Printf("AnimeGo config v%s\n", configs.ConfigVersion)
36+
fmt.Printf("%s\n", constant.AnimeGoGithub)
37+
fmt.Println("--------------------------------------------------")
38+
}
39+
40+
func RegisterExit(doExit func()) {
41+
sigs := make(chan os.Signal, 1)
42+
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
43+
go func() {
44+
for s := range sigs {
45+
switch s {
46+
case syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT:
47+
pkgLog.Infof("收到退出信号: %v", s)
48+
doExit()
49+
default:
50+
pkgLog.Infof("收到其他信号: %v", s)
51+
}
52+
}
53+
}()
54+
}

0 commit comments

Comments
 (0)