本文整理汇总了Golang中github.com/orktes/captainhub/Godeps/_workspace/src/github.com/labstack/echo.Context.Request方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Request方法的具体用法?Golang Context.Request怎么用?Golang Context.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/orktes/captainhub/Godeps/_workspace/src/github.com/labstack/echo.Context
的用法示例。
在下文中一共展示了Context.Request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: payload
// Handler
func payload(c *echo.Context) error {
var owner string
var repo string
r := c.Request()
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
if hookSecret != "" {
sig := r.Header.Get("X-Hub-Signature")
if sig == "" {
return errMissingSig
}
mac := hmac.New(sha1.New, []byte(hookSecret))
mac.Write(body)
expectedMAC := mac.Sum(nil)
expectedSig := "sha1=" + hex.EncodeToString(expectedMAC)
if !hmac.Equal([]byte(expectedSig), []byte(sig)) {
return errInvalidSig
}
}
eventType := r.Header.Get("X-Github-Event")
data := map[string]interface{}{}
if err := json.Unmarshal(body, &data); err != nil {
fmt.Printf("%s", err.Error())
return err
}
repository := data["repository"]
repoMap, ok := repository.(map[string]interface{})
if !ok {
fmt.Printf("Repository missing")
return nil
}
repo = repoMap["name"].(string)
ownerMap, ok := repoMap["owner"].(map[string]interface{})
if !ok {
fmt.Printf("Owner missing")
return nil
}
if _, ok := ownerMap["login"]; ok {
owner = ownerMap["login"].(string)
} else if _, ok := ownerMap["name"]; ok {
owner = ownerMap["name"].(string)
}
fmt.Printf("Event: %s, Owner: %s, Repo %s\n", eventType, owner, repo)
cfg, err := getCaptainConfig(owner, repo)
fmt.Printf("%s/%s config: %+v\n", owner, repo, cfg)
if err != nil {
return err
}
for _, plugin := range cfg.Plugins {
pluginData, err := getCaptainPlugin(owner, repo, plugin.Name)
if err != nil {
// TODO set info about this
fmt.Printf("%s", err.Error())
continue
}
vm := otto.New()
vm.Run(`
var global = {};
_moduleCache = {};
function require(moduleName) {
if (!_moduleCache[moduleName]) {
_require(moduleName);
}
return _moduleCache[moduleName];
}
`)
vm.Set("eventType", eventType)
vm.Set("eventData", data)
vm.Set("config", plugin.Config)
vm.Set("matchFilePath", matchFilePath)
vm.Set("_require", func(call otto.FunctionCall) otto.Value {
moduleFilename, err := call.Argument(0).ToString()
if err != nil {
panic(err)
}
content, err := getCaptainPlugin(owner, repo, moduleFilename)
//.........这里部分代码省略.........