本文整理匯總了Golang中github.com/eaciit/colony-manager/helper.CreateResult函數的典型用法代碼示例。如果您正苦於以下問題:Golang CreateResult函數的具體用法?Golang CreateResult怎麽用?Golang CreateResult使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CreateResult函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SearchApps
func (a *ApplicationController) SearchApps(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
text := "Mandiri"
var query *dbox.Filter
if text != "" {
// query = dbox.Or(dbox.Eq("AppsName", text), dbox.Eq("ID", text))
query = dbox.Eq("AppsName", text)
}
cursor, err := colonycore.Find(new(colonycore.Application), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
data := []colonycore.Application{}
err = cursor.Fetch(&data, 0, false)
fmt.Println("data pencarian : ", data)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例2: SaveScrapperData
func (w *WebGrabberController) SaveScrapperData(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := new(colonycore.WebGrabber)
err := r.GetPayload(payload)
fmt.Printf("\n=============\n")
fmt.Printf("%#v", payload)
fmt.Printf("\n=============\n")
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = colonycore.Delete(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = colonycore.Save(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
fmt.Printf("\n=============\n")
fmt.Printf("%#v", payload)
fmt.Printf("\n=============\n")
return helper.CreateResult(true, payload, "")
}
示例3: RemoveConnection
func (d *DataSourceController) RemoveConnection(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())
}
id := payload["_id"].(string)
ds := new(colonycore.DataSource)
cursor, err := colonycore.Find(ds, dbox.Eq("ConnectionID", id))
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
if cursor.Count() > 0 {
return helper.CreateResult(false, nil, "Cannot delete connection because used on data source")
}
o := new(colonycore.Connection)
o.ID = id
err = colonycore.Delete(o)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, nil, "")
}
示例4: RemoveChart
func (wc *WidgetChartController) RemoveChart(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := map[string]interface{}{}
if err := r.GetPayload(&payload); !helper.HandleError(err) {
return helper.CreateResult(false, nil, err.Error())
}
idArray := payload["_id"].([]interface{})
for _, id := range idArray {
mapchart := new(colonycore.MapChart)
mapchart.ID = id.(string)
if err := mapchart.Delete(); !helper.HandleError(err) {
return helper.CreateResult(false, nil, err.Error())
}
filechart := new(colonycore.Chart)
filechart.ID = id.(string)
if err := filechart.Remove(); !helper.HandleError(err) {
return helper.CreateResult(false, nil, err.Error())
}
}
return helper.CreateResult(true, payload["_id"], "")
}
示例5: GetFetchedData
func (w *WebGrabberController) GetFetchedData(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
w.PrepareHistoryPath()
payload := struct {
Driver string
Host string
Database string
Collection string
Username string
Password string
}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
var data []toolkit.M
if payload.Driver == "csv" {
config := toolkit.M{"useheader": true, "delimiter": ","}
query := helper.Query("csv", payload.Host, "", "", "", config)
data, err = query.SelectAll("")
} else {
query := helper.Query("mongo", payload.Host, payload.Database, payload.Username, payload.Password)
data, err = query.SelectAll(payload.Collection)
}
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, data, "")
}
示例6: FetchDataSourceMetaData
func (d *DataSourceController) FetchDataSourceMetaData(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)
from := payload["from"].(string)
if connectionID == "" {
return helper.CreateResult(true, []toolkit.M{}, "")
}
dataConn := new(colonycore.Connection)
err = colonycore.Get(dataConn, connectionID)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
res, data, err := d.DoFetchDataSourceMetaData(dataConn, from)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(res, data, "")
}
示例7: NewFile
func (s *FileBrowserController) NewFile(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
server, payload, err := getServer(r, "PAYLOAD")
fmt.Println("aaaaa")
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
if server.RecordID() != nil {
if payload.Path != "" {
if server.ServerType == SERVER_NODE {
setting, err := sshConnect(&server)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = sshclient.MakeFile(setting, " ", payload.Path, "", false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, nil, "")
} else if server.ServerType == SERVER_HDFS {
h := setHDFSConnection(server.Host, server.SSHUser)
//create file on local
tempPath := strings.Replace(GetHomeDir()+"/", "//", "/", -1)
if tempPath == "" {
return helper.CreateResult(false, nil, "No Temporary Directory")
}
FileName := strings.Split(payload.Path, "/")[len(strings.Split(payload.Path, "/"))-1]
file, err := os.Create(tempPath + FileName)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer file.Close()
//put new file to hdfs
err = h.Put(tempPath+FileName, strings.Replace(payload.Path+"/", "//", "/", -1), "", nil, &server)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
//remove file on local
// err = os.Remove(tempPath + FileName)
// if err != nil {
// return helper.CreateResult(false, nil, err.Error())
// }
return helper.CreateResult(true, "", "")
}
}
return helper.CreateResult(false, nil, "Please check your param")
}
return helper.CreateResult(false, nil, "")
}
示例8: SaveDataGrabber
func (d *DataGrabberController) SaveDataGrabber(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := new(colonycore.DataGrabber)
err := r.GetPayload(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
before := new(colonycore.DataGrabber)
err = colonycore.Get(before, payload.ID)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = colonycore.Delete(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
payload.RunAt = before.RunAt
err = colonycore.Save(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, payload, "")
}
示例9: RemoveMultipleWebGrabber
func (w *WebGrabberController) RemoveMultipleWebGrabber(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())
}
idArray := payload["_id"].([]interface{})
for _, id := range idArray {
o := new(colonycore.WebGrabber)
o.ID = id.(string)
err = colonycore.Delete(o)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
}
if err := w.SyncConfig(); err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, nil, "")
}
示例10: FindUserLdap
func (a *GroupController) FindUserLdap(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())
}
addr := payload["Address"].(string)
basedn := payload["BaseDN"].(string)
filter := payload["Filter"].(string)
username := payload["Username"].(string)
password := payload["Password"].(string)
var attr []string
err = toolkit.Serde(payload["Attribute"], &attr, "json")
if err != nil {
return helper.CreateResult(false, err, "error")
}
param := toolkit.M{}
param.Set("username", username)
param.Set("password", password)
param.Set("attributes", attr)
arrm, err := acl.FindDataLdap(addr, basedn, filter, param)
if err != nil {
return helper.CreateResult(false, err, "error")
}
return helper.CreateResult(true, arrm, "success")
}
示例11: 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, "")
}
示例12: SaveGroupConfigLdap
func (a *GroupController) SaveGroupConfigLdap(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.Ldap)
o.ID = payload["Address"].(string)
o.Address = payload["Address"].(string)
o.BaseDN = payload["BaseDN"].(string)
o.FilterGroup = payload["Filter"].(string)
o.Username = payload["Username"].(string)
//o.Password = payload["Password"].(string)
err = toolkit.Serde(payload["Attribute"], &o.AttributesGroup, "json")
if err != nil {
return helper.CreateResult(false, err.Error(), "error")
}
err = colonycore.Save(o)
if err != nil {
return helper.CreateResult(false, o, err.Error())
}
return helper.CreateResult(true, o, "")
}
示例13: GetLdapdataAddress
func (a *GroupController) GetLdapdataAddress(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
autoFilters := []*dbox.Filter{}
var query *dbox.Filter
if len(autoFilters) > 0 {
query = dbox.And(autoFilters...)
}
cursor, err := colonycore.Find(new(colonycore.Ldap), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
data := []colonycore.Ldap{}
err = cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例14: SaveServers
func (s *ServerController) SaveServers(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())
// }
data := new(colonycore.Server)
data.ID = "192.168.0.200"
data.Type = "local"
data.Folder = "/data"
data.OS = "linux"
data.Enable = true
data.SSHType = "DDL: Credential"
data.SSHFile = "knot-server"
data.SSHUser = "knot"
data.SSHPass = "knotpass"
err := colonycore.Delete(data)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = colonycore.Save(data)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
// Printf("data:%v\n", data)
return helper.CreateResult(true, nil, "")
}
示例15: SavePassword
func (l *LoginController) SavePassword(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := toolkit.M{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
if !payload.Has("newpassword") || !payload.Has("userid") {
return helper.CreateResult(false, nil, "Data is not complete")
}
switch {
case payload.Has("tokenid"):
err = acl.ChangePasswordToken(toolkit.ToString(payload["userid"]), toolkit.ToString(payload["newpassword"]), toolkit.ToString(payload["tokenid"]))
default:
// check sessionid first
savedsessionid := "" //change with get session
//=======================
userid, err := acl.FindUserBySessionID(savedsessionid)
if err == nil && userid == toolkit.ToString(payload["userid"]) {
err = acl.ChangePassword(toolkit.ToString(payload["userid"]), toolkit.ToString(payload["newpassword"]))
} else if err == nil {
err = errors.New("Userid is not match")
}
}
return helper.CreateResult(true, nil, "save password success")
}