feat: cc-hook v1.0 - Claude Code 钩子服务
- Go HTTP 服务,监听 :8082 - 支持 Notification 和 Stop 事件 - 转发至 Gotify 推送通知 - Docker 多阶段构建 - 环境变量配置 - 详细中文 README 文档
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SendMessage(gotifyURL, token, title, message string, priority int) error {
|
||||
endpoint := fmt.Sprintf("%s/message?token=%s", gotifyURL, token)
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("title", title)
|
||||
form.Set("message", message)
|
||||
form.Set("priority", fmt.Sprintf("%d", priority))
|
||||
|
||||
resp, err := http.Post(endpoint, "application/x-www-form-urlencoded", strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send gotify message: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("gotify returned status %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user