當前位置: 首頁>>代碼示例>>Golang>>正文


Golang wk.Data函數代碼示例

本文整理匯總了Golang中github.com/sdming/wk.Data函數的典型用法代碼示例。如果您正苦於以下問題:Golang Data函數的具體用法?Golang Data怎麽用?Golang Data使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Data函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Set

// url: /basic/set/32?str=s&uint=64&float=3.14&byte=8
func (c *BasicController) Set(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	var id int

	if i, ok := ctx.RouteData.Int("id"); ok {
		id = i
	} else {
		return wk.Data(0), nil
	}

	var count int = 0
	for i := 0; i < len(c.data); i++ {
		d := c.data[i]

		if d.Int != id {
			continue
		}
		if x := ctx.FormValue("str"); x != "" {
			d.Str = x
		}
		if x, ok := ctx.FormInt("uint"); ok {
			d.Uint = uint64(x)
		}
		if x, ok := ctx.FormFloat("float"); ok {
			d.Float = float32(x)
		}
		if x, ok := ctx.FormInt("byte"); ok {
			d.Byte = byte(x)
		}
		count++
	}

	return wk.Data(count), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:34,代碼來源:basic.go

示例2: Query

// url: /config/query
func (c *ConfigController) Query(ctx *wk.HttpContext) (wk.HttpResult, error) {
	// maybe support "a b[@field=xxx] c d " later
	n, ok := c.node().Query("key_config Db_Log Host")
	if ok {
		return wk.Data(n.Literal), nil
	}
	return wk.Data(ok), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:9,代碼來源:config.go

示例3: Delete

// url: /basic/delete/32
func (c *BasicController) Delete(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	l := len(c.data)
	if i, ok := ctx.RouteData.Int("id"); ok {
		c.deleteByInt(i)
	}
	return wk.Data(l - len(c.data)), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:8,代碼來源:basic.go

示例4: Map

// url: /config/map
func (c *ConfigController) Map(ctx *wk.HttpContext) (wk.HttpResult, error) {
	data, err := c.node().MustChild("key_map").Map()
	if err != nil {
		return nil, err
	}
	return wk.Data(data), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:8,代碼來源:config.go

示例5: Exists

// get: /user/exists/sheldon
func (uc *UserController) Exists(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	valid := true
	if name := ctx.FV("name"); name != "" {
		valid = !userRepo.Exists(name)
	}
	return wk.Data(valid), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:8,代碼來源:user.go

示例6: Composite

// url: /config/composite
func (c *ConfigController) Composite(ctx *wk.HttpContext) (wk.HttpResult, error) {
	conf := &Config{}
	err := c.node().MustChild("key_config").Value(conf)
	if err != nil {
		return nil, err
	}
	return wk.Data(conf), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:9,代碼來源:config.go

示例7: Bool

// url: /config/bool
func (c *ConfigController) Bool(ctx *wk.HttpContext) (wk.HttpResult, error) {
	//Int, Uint, Float, Bool, String
	b, err := c.node().MustChild("key_bool").Bool()
	if err != nil {
		return nil, err
	}
	return wk.Data(b), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:9,代碼來源:config.go

示例8: Add

// url: /basic/add/?int=32&str=string&uint=1024&float=1.1&byte=64
func (c *BasicController) Add(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	data := Data{
		Int:   ctx.FormIntOr("int", 0),
		Uint:  uint64(ctx.FormIntOr("uint", 0)),
		Str:   ctx.FormValue("str"),
		Float: float32(ctx.FormFloatOr("float", 0.0)),
		Byte:  byte(ctx.FormIntOr("byte", 0)),
	}
	c.data = append(c.data, data)
	return wk.Data(data.String()), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:12,代碼來源:basic.go

示例9: RangeCount

// url: /basic/rangecount/?start=1&end=99
func (c *BasicController) RangeCount(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	start := ctx.FormIntOr("start", 0)
	end := ctx.FormIntOr("end", 0)
	var count int = 0

	for _, d := range c.data {
		if d.Int >= start && d.Int <= end {
			count++
		}
	}
	return wk.Data(count), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:13,代碼來源:basic.go

示例10: Post

// url: post /basic/post/
func (c *BasicController) Post(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	var body []byte
	if body, err = ctx.ReadBody(); err != nil {
		return nil, err
	}

	data := &Data{}
	err = json.Unmarshal(body, data)
	if err != nil {
		return nil, err
	}
	c.data = append(c.data, *data)
	return wk.Data(true), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:15,代碼來源:basic.go

示例11: Value

// url: /config/value
func (c *ConfigController) Value(ctx *wk.HttpContext) (wk.HttpResult, error) {
	v := Driver{
		Driver:   "driver",
		Host:     "host",
		User:     "user",
		Password: "password",
		A:        "aaa",
		B:        "bbb",
	}

	err := c.node().MustChild("key_struct").Value(&v)
	if err != nil {
		return nil, err
	}
	return wk.Data(v), nil
}
開發者ID:jango2015,項目名稱:wk,代碼行數:17,代碼來源:config.go

示例12: Keys

// url: /session/keys
func (c *Session) Keys(ctx *wk.HttpContext) (wk.HttpResult, error) {
	keys, err := ctx.Session.Keys()
	return wk.Data(fmt.Sprintln(keys)), err
}
開發者ID:jango2015,項目名稱:wk,代碼行數:5,代碼來源:session.go

示例13: Abandon

// url: /session/abandon
func (c *Session) Abandon(ctx *wk.HttpContext) (wk.HttpResult, error) {
	err := ctx.Session.Abandon()
	return wk.Data(true), err
}
開發者ID:jango2015,項目名稱:wk,代碼行數:5,代碼來源:session.go

示例14: Remove

// url: /session/remove?k=test
func (c *Session) Remove(ctx *wk.HttpContext) (wk.HttpResult, error) {
	err := ctx.Session.Remove(ctx.FV("k"))
	return wk.Data(err == nil), err
}
開發者ID:jango2015,項目名稱:wk,代碼行數:5,代碼來源:session.go

示例15: Get

// url: /session/get?k=test
func (c *Session) Get(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	v, _, err := ctx.Session.Get(ctx.FV("k"))
	return wk.Data(v), err
}
開發者ID:jango2015,項目名稱:wk,代碼行數:5,代碼來源:session.go


注:本文中的github.com/sdming/wk.Data函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。