GolangHook类实例源码

您所在的位置:网站首页 github账号共享 GolangHook类实例源码

GolangHook类实例源码

2024-07-04 03:39:44| 来源: 网络整理| 查看: 265

Golang Hook类(方法)实例源码

Golang是Google开发的编程语言,在高并发方面性能优越,甚至有超越java的可能,学习和使用的人也越来越多, 如果你是初学者,希望了解Golang Hook类(方法)源码的使用方法, 可以查看下面的Golang Hook类(方法)源码代码实例,从而了解它的用法。 如果你正在从事Golang工作,想要使用Golang Hook类(方法)源码编写项目,也可以从下面的代码实例中获得帮助。该实例来源于Golang真实项目总结, 通过简单修改,就可以快速一移植到你自己的项目当中。 你可以选中该类(或者方法)Hook源码,按ctrl+f,通过浏览器的搜索方法,这样该会高亮显示,从而快速定位该类所在代码位置,更好了解它的用法。

作者:zankar    项目:dron    // ParsePullRequestHook parses the pull request hook from the Request body // and returns the required data in a standard format. func (r *GitHub) ParsePullRequestHook(req *http.Request) (*model.Hook, error) { // parse the payload to retrieve the pull-request // hook meta-data. var payload = GetPayload(req) var data, err = github.ParsePullRequestHook(payload) if err != nil { return nil, err } // ignore these if data.Action != "opened" && data.Action != "synchronize" { return nil, nil } // TODO we should also store the pull request branch (ie from x to y) // we can find it here: data.PullRequest.Head.Ref var hook = model.Hook{ Owner: data.Repo.Owner.Login, Repo: data.Repo.Name, Sha: data.PullRequest.Head.Sha, Branch: data.PullRequest.Head.Ref, Author: data.PullRequest.User.Login, Gravatar: data.PullRequest.User.GravatarId, Timestamp: time.Now().UTC().String(), Message: data.PullRequest.Title, PullRequest: strconv.Itoa(data.Number), } if len(hook.Owner) == 0 { hook.Owner = data.Repo.Owner.Name } return &hook, nil } 作者:carnivalmobil    项目:dron    // ParseHook parses the post-commit hook from the Request body // and returns the required data in a standard format. func (r *Gitlab) ParseHook(req *http.Request) (*model.Hook, error) { defer req.Body.Close() var payload, _ = ioutil.ReadAll(req.Body) var parsed, err = gogitlab.ParseHook(payload) if err != nil { return nil, err } if len(parsed.After) == 0 || parsed.TotalCommitsCount == 0 { return nil, nil } if parsed.ObjectKind == "merge_request" { // TODO (bradrydzewski) figure out how to handle merge requests return nil, nil } if len(parsed.After) == 0 { return nil, nil } var hook = new(model.Hook) hook.Owner = req.FormValue("owner") hook.Repo = req.FormValue("name") hook.Sha = parsed.After hook.Branch = parsed.Branch() var head = parsed.Head() hook.Message = head.Message hook.Timestamp = head.Timestamp // extracts the commit author (ideally email) // from the post-commit hook switch { case head.Author != nil: hook.Author = head.Author.Email case head.Author == nil: hook.Author = parsed.UserName } return hook, nil } 作者:zankar    项目:dron    // ParseHook parses the post-commit hook from the Request body // and returns the required data in a standard format. func (r *GitHub) ParseHook(req *http.Request) (*model.Hook, error) { // handle github ping if req.Header.Get("X-Github-Event") == "ping" { return nil, nil } // handle github pull request hook differently if req.Header.Get("X-Github-Event") == "pull_request" { return r.ParsePullRequestHook(req) } // parse the github Hook payload var payload = GetPayload(req) var data, err = github.ParseHook(payload) if err != nil { return nil, nil } // make sure this is being triggered because of a commit // and not something like a tag deletion or whatever if data.IsTag() || data.IsGithubPages() || data.IsHead() == false || data.IsDeleted() { return nil, nil } var hook = new(model.Hook) hook.Repo = data.Repo.Name hook.Owner = data.Repo.Owner.Login hook.Sha = data.Head.Id hook.Branch = data.Branch() if len(hook.Owner) == 0 { hook.Owner = data.Repo.Owner.Name } // extract the author and message from the commit // this is kind of experimental, since I don't know // what I'm doing here. if data.Head != nil && data.Head.Author != nil { hook.Message = data.Head.Message hook.Timestamp = data.Head.Timestamp hook.Author = data.Head.Author.Email } else if data.Commits != nil && len(data.Commits) > 0 && data.Commits[0].Author != nil { hook.Message = data.Commits[0].Message hook.Timestamp = data.Commits[0].Timestamp hook.Author = data.Commits[0].Author.Email } return hook, nil }


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭