本文整理匯總了Golang中github.com/eaciit/dbox.Contains函數的典型用法代碼示例。如果您正苦於以下問題:Golang Contains函數的具體用法?Golang Contains怎麽用?Golang Contains使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Contains函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetDataSources
func (d *DataSourceController) GetDataSources(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())
}
search := payload["search"].(string)
var query *dbox.Filter
query = dbox.Or(dbox.Contains("_id", search), dbox.Contains("ConnectionID", search))
cursor, err := colonycore.Find(new(colonycore.DataSource), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
data := []colonycore.DataSource{}
err = cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例2: FindDataGrabber
func (d *DataGrabberController) FindDataGrabber(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
//~ payload := map[string]string{"inputText":"test"}
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
text := payload["inputText"].(string)
textLow := strings.ToLower(text)
var query *dbox.Filter
valueInt, errv := strconv.Atoi(text)
fmt.Printf("", valueInt)
fmt.Printf("", errv)
if errv == nil {
// == try useing Eq for support integer
query = dbox.Or(dbox.Eq("GrabInterval", valueInt), dbox.Eq("TimeoutInterval", valueInt))
} else {
// == try useing Contains for support autocomplite
query = dbox.Or(dbox.Contains("_id", text), dbox.Contains("_id", textLow), dbox.Contains("DataSourceOrigin", text), dbox.Contains("DataSourceOrigin", textLow), dbox.Contains("DataSourceDestination", text), dbox.Contains("DataSourceDestination", textLow), dbox.Contains("IntervalType", text), dbox.Contains("IntervalType", textLow))
}
data := []colonycore.DataGrabber{}
cursor, err := colonycore.Find(new(colonycore.DataGrabber), query)
cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例3: GetListData
func (a *DataFlowController) GetListData(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())
}
search := tk.ToString(payload["search"])
var query *dbox.Filter
if search != "" {
query = dbox.Or(dbox.Contains("name", search), dbox.Contains("description", search), dbox.Contains("createdby", search))
}
cursor, err := colonycore.Find(new(colonycore.DataFlow), query)
dataDs := []colonycore.DataFlow{}
if cursor != nil {
cursor.Fetch(&dataDs, 0, false)
defer cursor.Close()
}
if err != nil && cursor != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, dataDs, "success")
}
示例4: FindConnection
func (d *DataSourceController) FindConnection(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
//~ payload := map[string]string{"inputText":"tes","inputDrop":""}
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
text := payload["inputText"].(string)
pilih := payload["inputDrop"].(string)
textLow := strings.ToLower(text)
// == try useing Contains for support autocomplite
var query *dbox.Filter
if text != "" {
query = dbox.Or(dbox.Contains("_id", text), dbox.Contains("_id", textLow), dbox.Contains("Database", text), dbox.Contains("Database", textLow), dbox.Contains("Driver", text), dbox.Contains("Driver", textLow), dbox.Contains("Host", text), dbox.Contains("Host", textLow), dbox.Contains("UserName", text), dbox.Contains("UserName", textLow), dbox.Contains("Password", text), dbox.Contains("Password", textLow))
}
if pilih != "" {
query = dbox.And(query, dbox.Eq("Driver", pilih))
}
data := []colonycore.Connection{}
cursor, err := colonycore.Find(new(colonycore.Connection), query)
cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例5: TestSelectCondition
func TestSelectCondition(t *testing.T) {
t.Skip("Just Skip Test")
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
csr, e := c.NewQuery().Select("Id", "LastName", "Age").
Where(dbox.Contains("LastName", "m")).
Take(10).Skip(0).
Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
resultsstruct := make([]employee, 0)
e = csr.Fetch(&resultsstruct, 0, false)
if e != nil {
t.Errorf("Unable to fetch N(0-10): %s \n", e.Error())
} else {
fmt.Printf("Record count(0-10) : %v \n", csr.Count())
fmt.Printf("Fetch N(0-10) OK. Result: %v \n", resultsstruct)
}
csr.Close()
csr, e = c.NewQuery().Select("Id", "LastName", "Age").
Where(dbox.Contains("LastName", "m")).
Take(10).Skip(10).
Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
resultsstruct = make([]employee, 0)
e = csr.Fetch(&resultsstruct, 0, false)
if e != nil {
t.Errorf("Unable to fetch N(10-20): %s \n", e.Error())
} else {
fmt.Printf("Record count(10-20) : %v \n", csr.Count())
fmt.Printf("Fetch N(10-20) OK. Result: %v \n", resultsstruct)
}
csr.Close()
}
示例6: GetServers
func (s *ServerController) GetServers(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := struct {
Search string `json:"search"`
ServerOS string `json:"serverOS"`
ServerType string `json:"serverType"`
SSHType string `json:"sshType"`
}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
filters := []*dbox.Filter{}
if payload.Search != "" {
filters = append(filters, dbox.Or(
dbox.Contains("_id", payload.Search),
dbox.Contains("os", payload.Search),
dbox.Contains("host", payload.Search),
dbox.Contains("serverType", payload.Search),
dbox.Contains("sshtype", payload.Search),
))
}
if payload.ServerOS != "" {
filters = append(filters, dbox.Eq("os", payload.ServerOS))
}
if payload.ServerType != "" {
filters = append(filters, dbox.Eq("serverType", payload.ServerType))
}
if payload.SSHType != "" {
filters = append(filters, dbox.Eq("sshtype", payload.SSHType))
}
var query *dbox.Filter
if len(filters) > 0 {
query = dbox.And(filters...)
}
cursor, err := colonycore.Find(new(colonycore.Server), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
data := []colonycore.Server{}
err = cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例7: TestFilter
func TestFilter(t *testing.T) {
fb := dbox.NewFilterBuilder(new(FilterBuilder))
fb.AddFilter(dbox.Or(
dbox.Contains("_id", "1"),
dbox.Contains("group", "adm", "test")))
b, e := fb.Build()
if e != nil {
t.Errorf("Error %s", e.Error())
} else {
fmt.Printf("Result:\n%v\n", toolkit.JsonString(b))
}
}
示例8: TestSelectFilter
func TestSelectFilter(t *testing.T) {
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
csr, e := c.NewQuery().Select().
Where(dbox.Contains("fullname", "43")).
From("TestUsers").Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
defer csr.Close()
results := make([]map[string]interface{}, 0)
e = csr.Fetch(&results, 10, false)
if e != nil {
t.Errorf("Unable to fetch N1: %s \n", e.Error())
} else {
fmt.Printf("Fetch N1 OK. Result: %v \n", results)
}
csr, e = c.NewQuery().
Where(dbox.Contains("fullname", "43", "44")).
From("TestUsers").Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
defer csr.Close()
results = make([]map[string]interface{}, 0)
e = csr.Fetch(&results, 10, false)
if e != nil {
t.Errorf("Unable to fetch N1: %s \n", e.Error())
} else {
fmt.Printf("Fetch N2 OK. Result: %v \n", results)
}
}
示例9: GetBrowser
func (d *DataBrowserController) GetBrowser(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())
}
search := payload["search"].(string)
// search = ""
var query *dbox.Filter
if search != "" {
query = dbox.Contains("BrowserName", search)
}
data := []colonycore.DataBrowser{}
cursor, err := colonycore.Find(new(colonycore.DataBrowser), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例10: GetSelectorConfigs
func (ws *WidgetSelectorController) GetSelectorConfigs(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())
}
var search string
search = payload["search"].(string)
var query *dbox.Filter
if search != "" {
query = dbox.Contains("_id", search)
}
data := []colonycore.Selector{}
cursor, err := colonycore.Find(new(colonycore.Selector), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例11: PrepareDefaultUser
func (l *LoginController) PrepareDefaultUser() (err error) {
username := colonycore.GetConfig("default_username", "").(string)
password := colonycore.GetConfig("default_password", "").(string)
user := new(acl.User)
filter := dbox.Contains("loginid", username)
c, err := acl.Find(user, filter, nil)
if err != nil {
return
}
if c.Count() == 0 {
user.ID = toolkit.RandomString(32)
user.LoginID = username
user.FullName = username
user.Password = password
user.Enable = true
err = acl.Save(user)
if err != nil {
return
}
err = acl.ChangePassword(user.ID, password)
if err != nil {
return
}
fmt.Printf(`Default user "%s" with standard password has been created%s`, username, "\n")
}
return
}
示例12: FindWebGrabber
func (d *WebGrabberController) FindWebGrabber(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
//~ payload := map[string]string{"inputText": "GRAB_TEST", "inputRequest": "", "inputType": ""}
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
text := payload["inputText"].(string)
req := payload["inputRequest"].(string)
tipe := payload["inputType"].(string)
textLow := strings.ToLower(text)
// == bug, cant find if autocomplite, just full text can be get result
var query *dbox.Filter
if text != "" {
valueInt, errv := strconv.Atoi(text)
if errv == nil {
// == try useing Eq for support integer
query = dbox.Or(dbox.Eq("GrabInterval", valueInt), dbox.Eq("TimeoutInterval", valueInt))
} else {
// == try useing Contains for support autocomplite
query = dbox.Or(dbox.Contains("_id", text), dbox.Contains("_id", textLow), dbox.Contains("Calltype", text), dbox.Contains("Calltype", textLow), dbox.Contains("SourceType", text), dbox.Contains("SourceType", textLow), dbox.Contains("IntervalType", text), dbox.Contains("IntervalType", textLow))
}
}
if req != "" {
query = dbox.And(query, dbox.Eq("Calltype", req))
}
if tipe != "" {
query = dbox.And(query, dbox.Eq("SourceType", tipe))
}
data := []colonycore.WebGrabber{}
cursor, err := colonycore.Find(new(colonycore.WebGrabber), query)
cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, payload, "")
}
示例13: GetUser
func (a *UserController) GetUser(r *knot.WebContext) interface{} {
var filter *dbox.Filter
r.Config.OutputType = knot.OutputJson
_ = a.InitialSetDatabase()
payload := map[string]interface{}{}
err := r.GetForms(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
if strings.Contains(toolkit.TypeName(payload["find"]), "float") {
payload["find"] = toolkit.ToInt(payload["find"], toolkit.RoundingAuto)
}
tUser := new(acl.User)
if find := toolkit.ToString(payload["find"]); find != "" {
filter = new(dbox.Filter)
filter = dbox.Or(dbox.Contains("id", find),
dbox.Contains("fullname", find),
dbox.Contains("email", find))
}
take := toolkit.ToInt(payload["take"], toolkit.RoundingAuto)
skip := toolkit.ToInt(payload["skip"], toolkit.RoundingAuto)
c, err := acl.Find(tUser, filter, toolkit.M{}.Set("take", take).Set("skip", skip))
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
data := toolkit.M{}
arrm := make([]toolkit.M, 0, 0)
err = c.Fetch(&arrm, 0, false)
c.Close()
c, err = acl.Find(tUser, filter, nil)
data.Set("Datas", arrm)
data.Set("total", c.Count())
if err != nil {
return helper.CreateResult(true, nil, err.Error())
} else {
return helper.CreateResult(true, data, "")
}
}
示例14: Search
func (a *GroupController) Search(r *knot.WebContext) interface{} {
var filter *dbox.Filter
r.Config.OutputType = knot.OutputJson
_ = a.InitialSetDatabase()
payload := map[string]interface{}{}
err := r.GetForms(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
if strings.Contains(toolkit.TypeName(payload["search"]), "float") {
payload["search"] = toolkit.ToInt(payload["search"], toolkit.RoundingAuto)
}
tGroup := new(acl.Group)
if search := toolkit.ToString(payload["search"]); search != "" {
filter = new(dbox.Filter)
filter = dbox.Or(dbox.Contains("_id", search), dbox.Contains("title", search), dbox.Contains("owner", search))
}
fmt.Println(filter)
take := toolkit.ToInt(payload["take"], toolkit.RoundingAuto)
skip := toolkit.ToInt(payload["skip"], toolkit.RoundingAuto)
c, err := acl.Find(tGroup, filter, toolkit.M{}.Set("take", take).Set("skip", skip))
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
data := toolkit.M{}
arrm := make([]toolkit.M, 0, 0)
err = c.Fetch(&arrm, 0, false)
data.Set("Datas", arrm)
data.Set("total", c.Count())
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
return helper.CreateResult(true, data, "")
}
示例15: GetAccess
func (a *AdministrationController) GetAccess(r *knot.WebContext) interface{} {
var filter *dbox.Filter
r.Config.OutputType = knot.OutputJson
a.InitialSetDatabase()
payload := map[string]interface{}{}
err := r.GetForms(&payload)
if strings.Contains(toolkit.TypeName(payload["find"]), "float") {
payload["find"] = toolkit.ToInt(payload["find"], toolkit.RoundingAuto)
}
tAccess := new(acl.Access)
if find := toolkit.ToString(payload["find"]); find != "" {
filter = new(dbox.Filter)
filter = dbox.Or(dbox.Contains("id", find),
dbox.Contains("title", find),
dbox.Contains("group1", find),
dbox.Contains("group2", find),
dbox.Contains("group3", find),
dbox.Contains("specialaccess1", find),
dbox.Contains("specialaccess2", find),
dbox.Contains("specialaccess3", find),
dbox.Contains("specialaccess4", find))
}
data := toolkit.M{}
arrm := make([]toolkit.M, 0, 0)
take := toolkit.ToInt(payload["take"], toolkit.RoundingAuto)
skip := toolkit.ToInt(payload["skip"], toolkit.RoundingAuto)
c, err := acl.Find(tAccess, filter, toolkit.M{}.Set("take", take).Set("skip", skip))
if err == nil {
err = c.Fetch(&arrm, 0, false)
}
c.Close()
c, err = acl.Find(tAccess, filter, nil)
data.Set("Datas", arrm)
data.Set("total", c.Count())
if err != nil {
return helper.CreateResult(true, nil, err.Error())
} else {
return helper.CreateResult(true, data, "")
}
}