當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.Request方法代碼示例

本文整理匯總了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)
//.........這裏部分代碼省略.........
開發者ID:orktes,項目名稱:captainhub,代碼行數:101,代碼來源:main.go


注:本文中的github.com/orktes/captainhub/Godeps/_workspace/src/github.com/labstack/echo.Context.Request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。