本文整理汇总了Golang中github.com/codegangsta/cli.Context.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Set方法的具体用法?Golang Context.Set怎么用?Golang Context.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.Set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runServer
func runServer(c *cli.Context) {
kit := utils.NewKit(c, conf)
kit.Engine = gin.Default()
kit.Engine.StaticFS("/static", &assetfs.AssetFS{
Asset: data.Asset,
AssetDir: data.AssetDir,
Prefix: "static",
})
kit.Engine.Use(func(c *gin.Context) {
c.Set("kit", kit)
})
// Avoid favicon react handling
kit.Engine.GET("/favicon.ico", func(c *gin.Context) {
c.Redirect(301, "/static/images/favicon.ico")
})
kit.Engine.GET("/api/v1/conf", api.ConfHandler)
kit.Engine.Use(func(c *gin.Context) {
id, _ := uuid.NewV4()
c.Set("uuid", id)
})
react.Bind(kit)
utils.Must(kit.Engine.Run(":" + kit.Conf.UString("port")))
}
示例2: ApplyTo
func (config FlagsConfig) ApplyTo(cmd string, c *cli.Context) error {
entry := config[""]
if cmd != "" {
entry.Apply(config[cmd])
}
vars := entry.Vars()
if cmd == "" {
vars["local"] = vars["global"]
vars["global"] = nil
}
for key, val := range vars["global"] {
if !c.GlobalIsSet(key) {
switch val.(type) {
case string:
strVal := val.(string)
if strVal == "" {
continue
}
c.GlobalSet(key, strVal)
case []string:
strSlice := val.([]string)
if len(strSlice) == 0 {
continue
}
for _, valBit := range strSlice {
c.GlobalSet(key, valBit)
}
default:
return fmt.Errorf(`unknown value type %T (%s: %+v)`, val, key, val)
}
}
}
for key, val := range vars["local"] {
if !c.IsSet(key) {
switch val.(type) {
case string:
strVal := val.(string)
if strVal == "" {
continue
}
c.Set(key, strVal)
case []string:
strSlice := val.([]string)
if len(strSlice) == 0 {
continue
}
for _, valBit := range strSlice {
c.Set(key, valBit)
}
default:
return fmt.Errorf(`unknown value type %T (%s: %+v)`, val, key, val)
}
}
}
return nil
}