本文整理匯總了Golang中github.com/gophergala2016/gophersiesta/server/storage.Storage.SetOption方法的典型用法代碼示例。如果您正苦於以下問題:Golang Storage.SetOption方法的具體用法?Golang Storage.SetOption怎麽用?Golang Storage.SetOption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gophergala2016/gophersiesta/server/storage.Storage
的用法示例。
在下文中一共展示了Storage.SetOption方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetValues
// SetValues set the placeholders values for a given appname and concrete namespace represented as labels
// If no labels are provided the "default" label is used
func SetValues(s storage.Storage) func(c *gin.Context) {
return func(c *gin.Context) {
name := c.Param("appname")
labels := c.DefaultQuery("labels", "default")
body := c.Request.Body
x, err := ioutil.ReadAll(body)
if err != nil {
c.String(http.StatusBadRequest, "Bad request")
} else {
data := map[string]interface{}{}
json.Unmarshal(x, &data)
lbls := strings.Split(labels, ",")
if len(data) > 0 { //it's a JSON
for _, label := range lbls {
for k, v := range data {
s.SetOption(name, label, k, fmt.Sprint(v))
}
}
c.String(http.StatusOK, "Ok")
} else if strings.Contains(string(x), "=") {
pairs := strings.Split(string(x), ",")
for _, label := range lbls {
for _, v := range pairs {
vv := strings.Split(v, "=")
s.SetOption(name, label, vv[0], strings.Join(vv[1:], "="))
}
}
c.String(http.StatusOK, "Ok")
} else {
c.String(http.StatusBadRequest, "Properties not well-formed")
}
}
}
}