1 Star 0 Fork 0

非一般/framework-iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
_examples
framework
src
commands
gen_annotation
annotation.go
command.go
comment.go
entity_controller.go
entity_crontab.go
entity_handler.go
entity_middleware.go
provider.go
resource.go
result_controller.go
result_crontab.go
result_handler.go
result_middleware.go
seeker.go
seeker_controller.go
seeker_crontab.go
seeker_handler.go
seeker_middleware.go
template_controller.tpl
template_crontab.tpl
template_handler.tpl
template_middleware.tpl
starter
stopper
common.go
conf
errs
logics
middlewares
application.go
application_test.go
component.go
controller_entry.go
handler_entry.go
parallel_runner.go
alias.go
alias_test.go
.gitignore
LICENSE
README.md
console
doc.go
go.mod
go.sum
克隆/下载
seeker_crontab.go 4.12 KB
一键复制 编辑 原始数据 按行查看 历史
非一般 提交于 11个月前 . new version
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-08-20
package gen_annotation
import (
_ "embed"
"fmt"
"gitee.com/go-libs/crontab"
"github.com/gorhill/cronexpr"
)
//go:embed template_crontab.tpl
var templateCrontab string
// SeekerCrontab
// is a component for crontab files manager.
type SeekerCrontab struct {
Seeker *Seeker
// Access fields.
result *ResultCrontab
target string
}
// Add
// adds a crontab file resource to manager.
func (o *SeekerCrontab) Add(resource *Resource) (err error) {
return resource.Reader(o.Seeker.Provider, o)
}
// Do
// generate and save to target file.
func (o *SeekerCrontab) Do() (err error) {
err = o.Seeker.Save(o.result.Ready(), o.target, templateCrontab)
return
}
// Match
// matches the line text of a resource file.
func (o *SeekerCrontab) Match(resource *Resource, comment *Comment, line int, text string) (err error) {
var (
entity *EntityCrontab
match []string
strategy string
)
// Match
// crontab name rule.
if m := ResourceRegexMatchCrontab.FindStringSubmatch(text); len(m) > 0 {
// Group type definition.
match = m
} else if n := ResourceRegexMatchCrontab2.FindStringSubmatch(text); len(n) > 0 {
// Single type definition.
match = n
}
// Return
// if not match on crontab.
if match == nil || len(match) == 0 {
return
}
// Creates
// a new entity.
entity = NewEntityCrontab(match[1])
entity.Import = resource.Import
entity.Package = resource.Package
entity.File = fmt.Sprintf(`%s/%s`, resource.Path, resource.Src)
entity.Line = line
// Range annotations.
for anno, list := range comment.GetAnnotations() {
switch anno {
case AnnotationCron:
// Strategy
// for crontab that defined with `@Cron()`.
for _, item := range list {
if s := item.First(); s != "" {
entity.Strategy = crontab.Strategy(s)
break
}
}
case AnnotationCronUnique:
// NodeUnique
// for crontab that defined with `@CronUnique()`.
for _, item := range list {
entity.NodeUnique = item.FirstBool()
break
}
case AnnotationCronGloballyUnique:
// GloballyUnique
// for crontab that defined with `@CronGloballyUnique()`.
for _, item := range list {
entity.GloballyUnique = item.FirstBool()
break
}
case AnnotationCronRunOnStartup:
// RunOnStartup
// for crontab that defined with `@CronRunOnStartup()`.
for _, item := range list {
entity.RunOnStartup = item.FirstBool()
break
}
}
}
// Strategy is required.
if strategy = entity.Strategy.String(); strategy == "" {
err = fmt.Errorf(`crontab strategy is required`)
return
}
// Strategy is invalid.
if _, err = cronexpr.Parse(strategy); err != nil {
err = fmt.Errorf(`crontab strategy is invalid: %s`, strategy)
return
}
// Parse succeed.
o.result.AddEntity(entity)
o.Seeker.Container.GetOutput().Info(` - found: source="%s/%s:%d", struct="%s", strategy="%s"`, resource.Path, resource.Src, line, entity.Struct, entity.Strategy)
return
}
// Target
// returns a file path for generated content.
func (o *SeekerCrontab) Target() string { return o.target }
// +---------------------------------------------------------------------------+
// | Access methods |
// +---------------------------------------------------------------------------+
func (o *SeekerCrontab) init() *SeekerCrontab {
o.result = NewResultCrontab(o.Seeker.Command, o.Seeker.Provider.AnnotationPkg)
o.target = fmt.Sprintf(`%s/%s/annotation_crontabs.go`, o.Seeker.Provider.WorkingDir, o.Seeker.Provider.AnnotationPath)
o.Seeker.Container.GetOutput().Info(`+ [scanner:crontab]`)
return o
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-wares/framework-iris.git
git@gitee.com:go-wares/framework-iris.git
go-wares
framework-iris
framework-iris
v1.1.8

搜索帮助