Golang 跨平台的 Webhook

文章原创首发地址

简单几步就能部署运行起来的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 等信息,由于过于简单且自解释,就不详解了,有问题的可以给我留言。

[
  {
    "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

项目主页
github

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,151评论 0 10
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 14,595评论 5 6
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,457评论 0 23
  • 这参加工作的一年多来,我零零散散地听到了她的一些消息,添了个儿子,搬出了小镇,调进了城里的中学,买了二手房,...
    詹惊蛰阅读 5,046评论 2 28
  • 好多人爱说物是人非,我更喜欢容若的燕子依然。有种代入感,好像还是当时当地,好像你还是我的我依然娇弱。 春暖花未开的...
    ns天微凉阅读 1,761评论 0 0