Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http客户端 #32

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

http客户端 #32

wants to merge 6 commits into from

Conversation

Jared-lu
Copy link
Contributor

#28 http客户端
Registry 里面我使用map存储用户注册的任务

type Registry struct {
	tasks map[string]EcronTask
}

客户端监听用户指定的 prefix,然后根据任务名去执行相应的Task

http.HandleFunc("$prefix", func(w http.ResponseWriter, r *http.Request) {
	name, _ := strings.CutPrefix(r.RequestURI, c.prefix)
	//POST => c.tasks[name].Task.Execute()
	//GET => c.tasks[name].Task.Status()
	//DELETE = >c.tasks[name].Task.Stop()
})

用户在注册任务时要保证任务名称不重复,否则会在注册时panic

client/http/client.go Outdated Show resolved Hide resolved
client/http/types.go Outdated Show resolved Hide resolved
client/http/registry.go Outdated Show resolved Hide resolved
client/http/client.go Outdated Show resolved Hide resolved
Copy link
Contributor

@flycash flycash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice,还有一点小问题,你改好后面我切下来写几个 example,重构看看效果

type HttpClient struct {
registry *Registry
host string // 用户服务器地址,如 http://localhost:8080
endpoint string // ecron服务器地址,如 http://www.ecron.com:80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你不需要这个!!!

return
}

t, exist := c.registry.tasks[name]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个定义到 registry 上,GetTask 这种方法

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尽量避免访问字段的字段,这不是一个好的习惯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实我就是想把大部分管理任务本身的方法挪过去 registry 里面,这个就只专注暴露为 HTTP 接口

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants