本文整理汇总了Golang中github.com/orktes/captainhub/Godeps/_workspace/src/github.com/labstack/echo.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createUser
func createUser(c *echo.Context) error {
u := new(user)
if err := c.Bind(u); err != nil {
return err
}
users[u.ID] = *u
return c.JSON(http.StatusCreated, u)
}
示例2: updateUser
func updateUser(c *echo.Context) error {
u := new(user)
if err := c.Bind(u); err != nil {
return err
}
id, _ := strconv.Atoi(c.Param("id"))
users[id].Name = u.Name
return c.JSON(http.StatusOK, users[id])
}
示例3: deleteUser
func deleteUser(c *echo.Context) error {
id, _ := strconv.Atoi(c.Param("id"))
delete(users, id)
return c.NoContent(http.StatusNoContent)
}
示例4: getUser
func getUser(c *echo.Context) error {
id, _ := strconv.Atoi(c.Param("id"))
return c.JSON(http.StatusOK, users[id])
}
示例5: hello
// Handler
func hello(c *echo.Context) error {
return c.String(http.StatusOK, "Hello, World!\n")
}
示例6: getUsers
func getUsers(c *echo.Context) error {
return c.JSON(http.StatusOK, users)
}
示例7: welcome
func welcome(c *echo.Context) error {
return c.Render(http.StatusOK, "welcome", "Joe")
}
示例8: 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)
//.........这里部分代码省略.........