本文整理汇总了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)
}
开发者ID:orktes,项目名称:captainhub,代码行数:8,代码来源:server.go
示例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])
}
开发者ID:orktes,项目名称:captainhub,代码行数:9,代码来源:server.go
示例3: deleteUser
func deleteUser(c *echo.Context) error {
id, _ := strconv.Atoi(c.Param("id"))
delete(users, id)
return c.NoContent(http.StatusNoContent)
}
开发者ID:orktes,项目名称:captainhub,代码行数:5,代码来源:server.go
示例4: getUser
func getUser(c *echo.Context) error {
id, _ := strconv.Atoi(c.Param("id"))
return c.JSON(http.StatusOK, users[id])
}
开发者ID:orktes,项目名称:captainhub,代码行数:4,代码来源:server.go
示例5: hello
// Handler
func hello(c *echo.Context) error {
return c.String(http.StatusOK, "Hello, World!\n")
}
开发者ID:orktes,项目名称:captainhub,代码行数:4,代码来源:server.go
示例6: getUsers
func getUsers(c *echo.Context) error {
return c.JSON(http.StatusOK, users)
}
开发者ID:orktes,项目名称:captainhub,代码行数:3,代码来源:server.go
示例7: welcome
func welcome(c *echo.Context) error {
return c.Render(http.StatusOK, "welcome", "Joe")
}
开发者ID:orktes,项目名称:captainhub,代码行数:3,代码来源:server.go
示例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)
//.........这里部分代码省略.........
开发者ID:orktes,项目名称:captainhub,代码行数:101,代码来源:main.go
注:本文中的github.com/orktes/captainhub/Godeps/_workspace/src/github.com/labstack/echo.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论