本文整理汇总了Golang中encoding/json.Decoder类的典型用法代码### 示例。如果您正苦于以下问题:Golang Decoder类的具体用法?Golang Decoder怎么用?Golang Decoder使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。
在下文中一共展示了Decoder类的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: Telegram
// Telegram webhook
func Telegram(
context appengine.Context, decoder *json.Decoder, token string) string {
if token != teleToken {
return "!OK"
}
var teleEvent telePayload
decoder.Decode(&teleEvent)
message := teleEvent.Message
if strings.Index(message.Text, "/getcode") > -1 {
code := GetAlphaNumberic(6)
teleVerify := teleVerify{
ChatId: message.Chat.Id,
Code: code,
Date: time.Now(),
Name: message.Chat.First_name,
}
if message.Chat.Id < 0 {
teleVerify.Name = message.Chat.Title
}
key := datastore.NewIncompleteKey(
context, "teleVerify", teleVerifyKey(context, code))
datastore.Put(context, key, &teleVerify)
SendTeleMessage(context, code, message.Chat.Id)
} else if strings.Index(message.Text, "/start") > -1 {
SendTeleMessage(
context, "Welcome! Next step is to get registered with webhook.co",
message.Chat.Id)
} else if strings.Index(message.Text, "/help") > -1 {
SendTeleMessage(
context, "Get registered with webhook.co", message.Chat.Id)
}
return "OK"
}
开发者ID:PredictionGuru,项目名称:webhook,代码行数:34,代码来源:telegram.go
示例2: Load
func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
if err := decoder.Decode(&app); err != nil {
return err
}
if app.Css != nil {
app.Css.Dark = evalRelativePluginUrlPath(app.Css.Dark, app.Id)
app.Css.Light = evalRelativePluginUrlPath(app.Css.Light, app.Id)
}
app.PluginDir = pluginDir
app.initFrontendPlugin()
// check if we have child panels
for _, panel := range Panels {
if strings.HasPrefix(panel.PluginDir, app.PluginDir) {
panel.IncludedInAppId = app.Id
app.Includes = append(app.Includes, &AppIncludeInfo{
Name: panel.Name,
Id: panel.Id,
Type: panel.Type,
})
}
}
for _, page := range app.Pages {
if page.Slug == "" {
page.Slug = slug.Make(page.Name)
}
}
Apps[app.Id] = app
return nil
}
开发者ID:kaefik,项目名称:grafana,代码行数:34,代码来源:app_plugin.go
示例3: User
// User handles requests to query some user's info
func (uc *User) User(w *json.Encoder, r *json.Decoder, h *jsonapi.HTTP) {
res := new(Response)
var args map[string]interface{}
if err := r.Decode(&args); err != nil {
res.Fail("Arguments not in JSON format.")
return
}
ids, ok := args["userid"]
if !ok {
res.Fail("No user id passed.").Do(w)
return
}
uids, ok := ids.([]interface{})
if !ok || len(uids) < 1 {
res.Fail("No user id passed.").Do(w)
return
}
ret := make([]*model.User, 0, len(uids))
for _, uid := range uids {
u, err := model.LoadUser(int(uid.(float64))) // json numbers converts to float64 in go
if err != nil {
log.Printf("Error loading user from db: %s", err)
res.Fail("Error loading user from db").Do(w)
return
}
ret = append(ret, u)
}
res.Ok(ret).Do(w)
}
开发者ID:Patrolavia,项目名称:darius,代码行数:33,代码来源:user.go
示例4: UserRepos
func (c *Client) UserRepos(login string) (repos Repos, err error) {
res, err := c.Get(fmt.Sprintf("orgs/%s", login))
if err != nil {
res, err = c.Get(fmt.Sprintf("users/%s/repos", login))
} else {
res.Response.Body.Close()
res, err = c.Get(fmt.Sprintf("orgs/%s/repos", login))
}
defer res.Response.Body.Close()
if err != nil {
return
}
var r Repos
var dec *json.Decoder
for res != nil {
dec = json.NewDecoder(res.Response.Body)
err = dec.Decode(&r)
if err != nil {
return nil, err
}
repos = append(repos, r...)
res = res.NextPage()
}
return
}
开发者ID:VictorLowther,项目名称:go-github,代码行数:25,代码来源:repos.go
示例5: Handle
func (h *add) Handle(dec *json.Decoder, httpData *jsonapi.HTTP) (ret interface{}, err error) {
type p struct {
Data Order `json:"data"`
Token string `json:"token"`
}
var param p
if err := dec.Decode(¶m); err != nil {
return nil, jsonapi.Error{http.StatusBadRequest, "Parameter is not Order object"}
}
if !h.A.Valid(param.Token) {
return nil, jsonapi.Error{http.StatusForbidden, "Invalid token"}
}
// validating data
data := param.Data
data.Code = strings.ToUpper(strings.TrimSpace(data.Code))
if len(data.Code) != 3 || data.Local == 0 || data.Foreign == 0 || data.Time <= 0 {
return nil, jsonapi.Error{http.StatusBadRequest, "Parameter has no Order object"}
}
if _, err := h.M.Insert("orders", data); err != nil {
return nil, jsonapi.Error{http.StatusInternalServerError, fmt.Sprintf("Error saving order: %s", err)}
}
return
}
开发者ID:Ronmi,项目名称:xchg,代码行数:28,代码来源:add.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng