Golang 跨平臺的 Webhook
ofollow,noindex">文章原創首發地址
簡單幾步就能部署執行起來的Webhook.
獲取webhook
wgethttps://github.com/adnanh/webhook/releases/download/2.6.8/webhook-linux-amd64.tar.gz
解壓縮
tar -zxvf ./webhook-linux-amd64.tar.gz
新增配置檔案
webhook.json update-qd1024.sh
其中webhook.json 是配置webhook id 等資訊,由於過於簡單且自解釋,就不詳解了,有問題的可以給我留言。
[ { "id": "webhook_update_qd1024", "execute-command": "update-qd1024.sh", "command-working-directory": "/home", } ]
update-qd1024.sh 就是具體執行命令的指令碼了,從中可以看出和gogs的配合。
#!/bin/bash cd /home/docker/gogs/www/qd1024 git --work-tree=/home/docker/gogs/www/qd1024 --git-dir=/home/docker/gogs/git/gogs-repositories/xin/qd1024.git checkout -f > git.log /home/hugo >hugo_qd1024.log
執行
寫好配置檔案,就是要跑起來。
後臺執行webhook
nohup /home/webhook/webhook -port 10100 -hotreload -hooks /home/webhook/webhook.json -verbose > webhook.log 2>&1 &
驗證
在gogo後臺新增webhook,並測試執行。
官方簡介
webhook is a lightweight configurable tool written in Go, that allows you to easily create HTTP endpoints (hooks) on your server, which you can use to execute configured commands. You can also pass data from the HTTP request (such as headers, payload or query variables) to your commands. webhook also allows you to specify rules which have to be satisfied in order for the hook to be triggered.
For example, if you're using Github or Bitbucket, you can use webhook to set up a hook that runs a redeploy script for your project on your staging server, whenever you push changes to the master branch of your project.
If you use Mattermost or Slack, you can set up an "Outgoing webhook integration" or "Slash command" to run various commands on your server, which can then report back directly to you or your channels using the "Incoming webhook integrations", or the appropriate response body.
webhook aims to do nothing more than it should do, and that is:
receive the request,
parse the headers, payload and query variables,
check if the specified rules for the hook are satisfied,
and finally, pass the specified arguments to the specified command via command line arguments or via environment variables.
Everything else is the responsibility of the command's author.
下載地址
專案主頁
github