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


Golang toolkit.HasMember函數代碼示例

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


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

示例1: HasPartExec

func (q *Query) HasPartExec() error {
	var e error
	var lastJson []toolkit.M

	q.ReadFile(&lastJson, q.Connection().(*Connection).filePath)
	if toolkit.SliceLen(lastJson) > 0 {
		getWhere := []*dbox.Filter{}
		for _, v := range q.whereData {
			getWhere = []*dbox.Filter{v}
			i := dbox.Find(q.sliceData, getWhere)

			for idSlice, _ := range q.sliceData {
				if toolkit.HasMember(i, idSlice) {
					idata := dbox.Find(lastJson, getWhere)
					for idx, _ := range lastJson {
						if toolkit.HasMember(idata, idx) {
							lastJson[idx] = q.sliceData[idSlice]
						}
					}
					if toolkit.SliceLen(idata) == 0 {
						lastJson = append(lastJson, q.sliceData[idSlice])
						// toolkit.Printf("idata>%v\n", q.sliceData[idSlice])
					}
				}
			}
		}
		q.sliceData = lastJson
	}

	e = q.WriteFile(q.sliceData)
	if e != nil {
		return errorlib.Error(packageName, modQuery+".Exec", "HasPartExec", e.Error())
	}
	return nil
}
開發者ID:Budianto55,項目名稱:dbox,代碼行數:35,代碼來源:json_query.go

示例2: MatchV

func MatchV(v interface{}, f *Filter) bool {
	match := false
	/*
		rv0 := reflect.ValueOf(v)
		if rv0.Kind() == reflect.Ptr {
			rv0 = reflect.Indirect(rv0)
		}
		rv1 := reflect.ValueOf(f.Value)
		if rv1.Kind()==reflect.Ptr{
			rv1=reflect.Indirect(rv1)
		}
	*/
	if toolkit.HasMember([]interface{}{FilterOpEqual, FilterOpNoEqual, FilterOpGt, FilterOpGte, FilterOpLt, FilterOpLte}, f.Op) {
		return Compare(v, f.Value, f.Op)
	} else if f.Op == FilterOpIn {
		var values []interface{}
		toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values)
		return toolkit.HasMember(values, v)
	} else if f.Op == FilterOpNin {
		var values []interface{}
		toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values)
		return !toolkit.HasMember(values, v)
	}
	return match
}
開發者ID:haibudi,項目名稱:dbox,代碼行數:25,代碼來源:dbox.go

示例3: DoFetchDataSourceMetaData

func (d *DataSourceController) DoFetchDataSourceMetaData(dataConn *colonycore.Connection, from string) (bool, []*colonycore.FieldInfo, error) {
	if err := d.checkIfDriverIsSupported(dataConn.Driver); err != nil {
		return false, nil, err
	}

	var conn dbox.IConnection
	conn, err := helper.ConnectUsingDataConn(dataConn).Connect()
	if err != nil {
		return false, nil, err
	}
	defer conn.Close()

	var query = conn.NewQuery().Take(1)

	if !toolkit.HasMember([]string{"csv", "json"}, dataConn.Driver) {
		query = query.From(from)
	}

	cursor, err := query.Cursor(nil)
	if err != nil {
		return false, nil, err
	}
	defer cursor.Close()

	data := toolkit.M{}

	var connDriver string
	if dataConn.Driver == "jdbc" {
		connDriver = strings.Split(dataConn.Settings.GetString("connector"), ":")[1]
	} else {
		connDriver = dataConn.Driver
	}

	if !toolkit.HasMember([]string{"json", "mysql"}, connDriver) {
		err = cursor.Fetch(&data, 1, false)
	} else {
		dataAll := []toolkit.M{}
		err = cursor.Fetch(&dataAll, 1, false)
		if err != nil {
			return false, []*colonycore.FieldInfo{}, errors.New("No data found")
		}

		if len(dataAll) > 0 {
			data = dataAll[0]
		}
	}

	metadata := d.parseMetadata(data)

	if err != nil {
		return false, nil, err
	}

	return true, metadata, nil
}
開發者ID:eaciit,項目名稱:colony-manager,代碼行數:55,代碼來源:datasource.go

示例4: HasPartExec

func (q *Query) HasPartExec() error {
	var e error
	var lastJson []toolkit.M

	q.ReadFile(&lastJson, q.Connection().(*Connection).filePath)
	if toolkit.SliceLen(lastJson) > 0 {
		getWhere := []*dbox.Filter{}
		for _, v := range q.whereData {
			getWhere = []*dbox.Filter{v}
			i := dbox.Find(q.sliceData, getWhere)

			for idSlice := range q.sliceData {
				if toolkit.HasMember(i, idSlice) {
					idata := dbox.Find(lastJson, getWhere)
					for idx := range lastJson {
						if toolkit.HasMember(idata, idx) {
							lastJson[idx] = q.sliceData[idSlice]
						}
					}
					if toolkit.SliceLen(idata) == 0 {
						lastJson = append(lastJson, q.sliceData[idSlice])
					}
				}
			}
		}
		q.sliceData = lastJson
	} else {
		idx := []int{}
		for _, v := range q.whereData {
			getWhere := []*dbox.Filter{v}
			idx = dbox.Find(q.sliceData, getWhere)

		}
		// toolkit.Printf("newdata>%v\n", idx)
		if toolkit.SliceLen(idx) > 1 {
			newdata := toolkit.M{}
			for idslice, dataslice := range q.sliceData {
				if toolkit.HasMember(idx, idslice) {
					idf, _ := toolkit.IdInfo(dataslice)
					newdata = q.sliceData[idslice]
					toolkit.CopyM(&dataslice, &newdata, false, []string{idf})
				}
			}
			q.sliceData = []toolkit.M{}
			q.sliceData = append(q.sliceData, newdata)
		}

	}

	e = q.WriteFile(q.sliceData)
	if e != nil {
		return errorlib.Error(packageName, modQuery+".Exec", "HasPartExec", e.Error())
	}
	return nil
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:55,代碼來源:json_query.go

示例5: MatchV

func MatchV(v interface{}, f *Filter) bool {
	match := false
	/*
		rv0 := reflect.ValueOf(v)
		if rv0.Kind() == reflect.Ptr {
			rv0 = reflect.Indirect(rv0)
		}
		rv1 := reflect.ValueOf(f.Value)
		if rv1.Kind()==reflect.Ptr{
			rv1=reflect.Indirect(rv1)
		}
	*/
	//toolkit.Println("MatchV: ", f.Op, v, f.Value)
	if toolkit.HasMember([]string{FilterOpEqual, FilterOpNoEqual, FilterOpGt, FilterOpGte, FilterOpLt, FilterOpLte}, f.Op) {
		return toolkit.Compare(v, f.Value, f.Op)
	} else if f.Op == FilterOpIn {
		var values []interface{}
		toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values)
		return toolkit.HasMember(values, v)
	} else if f.Op == FilterOpNin {
		var values []interface{}
		toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values)
		return !toolkit.HasMember(values, v)
	} else if f.Op == FilterOpContains {
		var values []interface{}
		var b bool
		toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values)

		for _, val := range values {
			// value := toolkit.Sprintf(".*%s.*", val.(string))
			// b, _ = regexp.Match(value, []byte(v.(string)))
			r := regexp.MustCompile(`(?i)` + val.(string))
			b = r.Match([]byte(v.(string)))
			if b {
				return true
			}
		}
	} else if f.Op == FilterOpStartWith || f.Op == FilterOpEndWith {
		value := ""
		if f.Op == FilterOpStartWith {
			value = toolkit.Sprintf("^%s.*$", f.Value)
		} else {
			value = toolkit.Sprintf("^.*%s$", f.Value)
		}
		cond, _ := regexp.Match(value, []byte(v.(string)))
		return cond
	}
	return match
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:49,代碼來源:dbox.go

示例6: extractData

func extractData(data toolkit.M, driverName string) (string, string, string) {
	var attributes, setUpdate, values string
	if data != nil {
		var i int
		for field, val := range data {
			var datatypelist = []string{"map", "invalid", "struct", "slice"}
			var value reflect.Value
			if val != nil {
				value = reflect.Zero(reflect.TypeOf(val))
			}
			if toolkit.HasMember(datatypelist, value.Kind().String()) {
				continue
			}
			stringValues := StringValue(val, driverName)
			if i == 0 {
				attributes = "(" + field
				setUpdate = field + " = " + stringValues
				values = "(" + stringValues

			} else {
				attributes += ", " + field
				setUpdate += ", " + field + " = " + stringValues
				values += ", " + stringValues

			}
			i += 1
		}
		attributes += ")"
		values += ")"
	}
	return attributes, setUpdate, values
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:32,代碼來源:rdbms_query.go

示例7: parseQuery

func (d *DataBrowserController) parseQuery(conn dbox.IConnection, dbrowser colonycore.DataBrowser, datacon *colonycore.Connection) (dbox.IQuery, error) {
	var dataQuery dbox.IQuery

	if dbrowser.QueryType == "nonQueryText" {
		dataQuery = conn.NewQuery().From(dbrowser.TableNames)
	} else if dbrowser.QueryType == "SQL" {
		if toolkit.HasMember(rdbms, datacon.Driver) {
			dataQuery = conn.NewQuery().Command("freequery", toolkit.M{}.
				Set("syntax", dbrowser.QueryText))
		} else {
			return nil, errors.New("Free Text Query with SQL only for RDBMS, please use Dbox")
		}
	} else if dbrowser.QueryType == "Dbox" {
		queryInfo := toolkit.M{}
		toolkit.UnjsonFromString(dbrowser.QueryText, &queryInfo)
		toolkit.Println("queryinfo", queryInfo)

		if qFrom := queryInfo.Get("from", "").(string); qFrom != "" {
			dataQuery = conn.NewQuery()
			dataQuery = dataQuery.From(qFrom)
		}
		if qSelect := queryInfo.Get("select", "").(string); qSelect != "" {
			if qSelect != "*" {
				dataQuery = dataQuery.Select(strings.Split(qSelect, ",")...)
			}
		}
	}
	return dataQuery, nil
}
開發者ID:kranjcarz,項目名稱:colony-manager,代碼行數:29,代碼來源:databrowser.go

示例8: extractDataBulk

func extractDataBulk(attrList []string, data toolkit.M, driverName string) string {
	var values string
	if data != nil {
		for i, attr := range attrList {
			val := data.Get(attr)
			var datatypelist = []string{"map", "invalid", "struct", "slice"}
			var value reflect.Value
			if val != nil {
				value = reflect.Zero(reflect.TypeOf(val))
			}
			if toolkit.HasMember(datatypelist, value.Kind().String()) {
				continue
			}
			stringValues := StringValue(val, driverName)
			if i == 0 {
				values = "(" + stringValues

			} else {
				values += ", " + stringValues

			}
		}
		values += ")"
	}
	return values
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:26,代碼來源:rdbms_query.go

示例9: ConnectUsingDataConn

func ConnectUsingDataConn(dataConn *colonycore.Connection) *queryWrapper {
	if toolkit.HasMember([]string{"json", "jsons", "csv", "csvs"}, dataConn.Driver) && strings.HasPrefix(dataConn.Host, "http") {
		return Query(dataConn.Driver, dataConn.FileLocation, "", "", "", dataConn.Settings)
	}

	return Query(dataConn.Driver, dataConn.Host, dataConn.Database, dataConn.UserName, dataConn.Password, dataConn.Settings)
}
開發者ID:nadnawidy,項目名稱:colony-manager,代碼行數:7,代碼來源:query.go

示例10: ConnectUsingDataConn

func ConnectUsingDataConn(dataConn *colonycore.Connection) *queryWrapper {
	if toolkit.HasMember([]string{"json", "jsons", "csv", "csvs"}, dataConn.Driver) && strings.HasPrefix(dataConn.Host, "http") {

		if toolkit.IsFileExist(dataConn.FileLocation) || dataConn.FileLocation == "" {
			fileTempID := RandomIDWithPrefix("f")
			fileType := GetFileExtension(dataConn.Host)
			dataConn.FileLocation = fmt.Sprintf("%s.%s", filepath.Join(os.Getenv("EC_DATA_PATH"), "datasource", "upload", fileTempID), fileType)

			file, err := os.Create(dataConn.FileLocation)
			if err != nil {
				os.Remove(dataConn.FileLocation)
			} else {
				defer file.Close()
			}

			resp, err := http.Get(dataConn.Host)
			if err != nil {
				os.Remove(dataConn.FileLocation)
			} else {
				defer resp.Body.Close()
			}

			_, err = io.Copy(file, resp.Body)
			if err != nil {
				os.Remove(dataConn.FileLocation)
			}

			colonycore.Save(dataConn)
		}

		return Query(dataConn.Driver, dataConn.FileLocation, "", "", "", dataConn.Settings)
	}

	return Query(dataConn.Driver, dataConn.Host, dataConn.Database, dataConn.UserName, dataConn.Password, dataConn.Settings)
}
開發者ID:rinosukmandityo,項目名稱:colony-manager,代碼行數:35,代碼來源:query.go

示例11: execQueryPartDelete

func (q *Query) execQueryPartDelete() error {
	var e error
	e = q.startWriteMode()
	if e != nil {
		return err.Error(packageName, modQuery, "Exec-Delete: ", e.Error())
	}

	writer := q.writer
	reader := q.reader
	tempHeader := []string{}

	for _, val := range q.headerColumn {
		tempHeader = append(tempHeader, val.name)
	}

	var i int = 0
	for {
		i += 1

		dataTemp, e := reader.Read()
		if e == io.EOF {
			if !toolkit.HasMember(q.indexes, i) && len(dataTemp) > 0 {
				writer.Write(dataTemp)
				writer.Flush()
			}
			break
		} else if e != nil {
			_ = q.endWriteMode()
			return err.Error(packageName, modQuery, "Exec-Delete: ", e.Error())
		}

		if !toolkit.HasMember(q.indexes, i) && len(dataTemp) > 0 {
			writer.Write(dataTemp)
			writer.Flush()
		}
	}

	q.execOpr = true
	e = q.endWriteMode()
	if e != nil {
		return err.Error(packageName, modQuery, "Exec-Delete: ", e.Error())
	}
	return nil

}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:45,代碼來源:query.go

示例12: SaveConnection

func (d *DataSourceController) SaveConnection(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]interface{}{}
	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	o := new(colonycore.Connection)
	o.ID = payload["_id"].(string)
	o.Driver = payload["Driver"].(string)
	o.Host = payload["Host"].(string)
	o.Database = payload["Database"].(string)
	o.UserName = payload["UserName"].(string)
	o.Password = payload["Password"].(string)
	o.Settings = d.parseSettings(payload["Settings"], map[string]interface{}{}).(map[string]interface{})

	err = colonycore.Delete(o)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	if toolkit.HasMember([]string{"csv", "json"}, o.Driver) {
		if strings.HasPrefix(o.Host, "http") {
			fileType := helper.GetFileExtension(o.Host)
			o.FileLocation = fmt.Sprintf("%s.%s", filepath.Join(EC_DATA_PATH, "datasource", "upload", o.ID), fileType)

			file, err := os.Create(o.FileLocation)
			if err != nil {
				return helper.CreateResult(false, nil, err.Error())
			}
			defer file.Close()

			resp, err := http.Get(o.Host)
			if err != nil {
				return helper.CreateResult(false, nil, err.Error())
			}
			defer resp.Body.Close()

			_, err = io.Copy(file, resp.Body)
			if err != nil {
				return helper.CreateResult(false, nil, err.Error())
			}
		} else {
			o.FileLocation = o.Host
		}
	}

	err = colonycore.Save(o)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	return helper.CreateResult(true, nil, "")
}
開發者ID:Budianto55,項目名稱:colony-manager,代碼行數:56,代碼來源:datasource.go

示例13: extractFields

func extractFields(data toolkit.M) []string {
	var attributes []string
	if data != nil {
		for field, val := range data {
			var datatypelist = []string{"map", "invalid", "struct", "slice"}
			var value reflect.Value
			if val != nil {
				value = reflect.Zero(reflect.TypeOf(val))
			}
			if toolkit.HasMember(datatypelist, value.Kind().String()) {
				continue
			}
			attributes = append(attributes, field)
		}
	}
	return attributes
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:17,代碼來源:rdbms_query.go

示例14: openFile

func (q *Query) openFile(commandtype string) error {
	if q.fileHasBeenOpened {
		return nil
	}

	_, e := os.Stat(q.jsonPath)
	setting := q.Connection().Info().Settings

	if e != nil && toolkit.HasMember([]interface{}{dbox.QueryPartSave, dbox.QueryPartInsert}, commandtype) &&
		strings.Contains(e.Error(), "cannot find the file specified") && setting != nil {
		newfile := setting.Get("newfile", false).(bool)
		if newfile {
			e = q.writeFile()
			if e != nil {
				return err.Error(packageName, modQuery, "openFile: "+commandtype+" Write fail", e.Error())
			}
		} else {
			return err.Error(packageName, modQuery, "openFile: "+commandtype+" Create new file is false", e.Error())
		}
	} else if e != nil && (strings.Contains(e.Error(), "does not exist") || strings.Contains(e.Error(), "no such file or directory")) {
		q.data = []toolkit.M{}
		return nil
	} else if e != nil {
		return err.Error(packageName, modQuery, "openFile: Open file fail", e.Error())
	}
	bs, e := ioutil.ReadFile(q.jsonPath)
	if e != nil {
		return err.Error(packageName, modQuery, "openFile: Read file data fail", e.Error())
	}
	jsonText := string(bs)
	var tempData []toolkit.M
	e = toolkit.UnjsonFromString(jsonText, &tempData)
	if e != nil {
		return err.Error(packageName, modQuery, "openFile: Serializaion fail", e.Error())
	}
	q.data = tempData

	q.fileHasBeenOpened = true
	return nil
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:40,代碼來源:query.go

示例15: GetDataSourceCollections

func (d *DataSourceController) GetDataSourceCollections(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]interface{}{}
	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	connectionID := payload["connectionID"].(string)
	if connectionID == "" {
		return helper.CreateResult(true, []string{}, "")
	}

	dataConn := new(colonycore.Connection)
	err = colonycore.Get(dataConn, connectionID)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	if err := d.checkIfDriverIsSupported(dataConn.Driver); err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	if toolkit.HasMember([]string{"csv", "json"}, dataConn.Driver) {
		return helper.CreateResult(true, []string{dataConn.Driver}, "")
	}

	var conn dbox.IConnection
	conn, err = helper.ConnectUsingDataConn(dataConn).Connect()
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer conn.Close()

	collections := conn.ObjectNames(dbox.ObjTypeTable)

	return helper.CreateResult(true, collections, "")
}
開發者ID:eaciit,項目名稱:colony-manager,代碼行數:38,代碼來源:datasource.go


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