Пример #1
0
func NewCondition(condition ConditionType, column string, param interface{}) Condition {
	var c Condition
	c.Type = condition
	c.Column = column
	c.Params = utils.ToSlice(param)
	return c
}
Пример #2
0
func rewriteSlice(a interface{}) interface{} {
	result := []interface{}{}
	values := utils.ToSlice(a)

	for _, v := range values {
		result = append(result, Rewrite(v))
	}
	return nil
}
Пример #3
0
func testDataUtil(t *testing.T) {
	var container []entities.User
	var user1 = entities.User{Id: 1, Name: "name1"}
	var user2 = entities.User{Id: 2, Name: "name2"}
	container = append(container, user1)
	container = append(container, user2)

	newContainer := utils.ToSlice(&container)
	for _, rowData := range newContainer {
		fmt.Println(rowData.(entities.User).Id)
	}
}
Пример #4
0
func (c *BaseController) toJsonResponse(key string, value interface{}, extraKeyValues ...interface{}) {

	keyValues := []interface{}{}
	keyValues = append(keyValues, key, value)

	for _, v := range extraKeyValues {
		val := reflect.ValueOf(v)
		sInd := reflect.Indirect(val)
		if sInd.Kind() == reflect.Slice {
			var s = utils.ToSlice(v)
			keyValues = append(keyValues, s...)
		} else {
			keyValues = append(keyValues, v)
		}
	}

	/*if (len(keyValues) % 2 != 0) {

	}*/
	var data = make(map[string]interface{})
	len := len(keyValues)
	for i := 0; i < len; i += 2 {
		var k string
		value, ok := keyValues[i].(string)
		if ok {
			k = value
		}
		v := keyValues[i+1]
		v = models.Rewrite(v)
		data[k] = v
	}

	c.Data["json"] = data
	c.ServeJSON()

}
Пример #5
0
func (p *Pagination) SetData(container interface{}) {
	p.Data = utils.ToSlice(container)
}