Golang 跨平臺(tái)的 Webhook

文章原創(chuàng)首發(fā)地址

簡(jiǎn)單幾步就能部署運(yùn)行起來(lái)的Webhook.

獲取webhook

wget https://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 等信息,由于過(guò)于簡(jiǎn)單且自解釋?zhuān)筒辉斀饬?,有?wèn)題的可以給我留言。

[
  {
    "id": "webhook_update_qd1024",
    "execute-command": "update-qd1024.sh",
    "command-working-directory": "/home",
  }
]

update-qd1024.sh 就是具體執(zhí)行命令的腳本了,從中可以看出和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

運(yùn)行

寫(xiě)好配置文件,就是要跑起來(lái)。
后臺(tái)運(yùn)行webhook

nohup /home/webhook/webhook -port 10100 -hotreload -hooks /home/webhook/webhook.json -verbose > webhook.log 2>&1 &

驗(yàn)證

在gogo后臺(tái)添加webhook,并測(cè)試運(yùn)行。

官方簡(jiǎn)介

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

項(xiàng)目主頁(yè)
github

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,862評(píng)論 0 10
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,664評(píng)論 5 6
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,160評(píng)論 0 23
  • 這參加工作的一年多來(lái),我零零散散地聽(tīng)到了她的一些消息,添了個(gè)兒子,搬出了小鎮(zhèn),調(diào)進(jìn)了城里的中學(xué),買(mǎi)了二手房,...
    詹驚蟄閱讀 1,350評(píng)論 2 28
  • 好多人愛(ài)說(shuō)物是人非,我更喜歡容若的燕子依然。有種代入感,好像還是當(dāng)時(shí)當(dāng)?shù)?,好像你還是我的我依然嬌弱。 春暖花未開(kāi)的...
    ns天微涼閱讀 275評(píng)論 0 0

友情鏈接更多精彩內(nèi)容