本文整理匯總了Golang中github.com/eaciit/toolkit.ToM函數的典型用法代碼示例。如果您正苦於以下問題:Golang ToM函數的具體用法?Golang ToM怎麽用?Golang ToM使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ToM函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getConfig
func getConfig() (err error) {
var result interface{}
if strings.Contains(configpath, "http") {
res, err := http.Get(configpath)
checkfatalerror(err)
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
err = decoder.Decode(&result)
checkfatalerror(err)
} else {
bytes, err := ioutil.ReadFile(configpath)
checkfatalerror(err)
err = json.Unmarshal(bytes, &result)
checkfatalerror(err)
}
switch toolkit.TypeName(result) {
case "[]interface {}":
isFound := false
for _, eachRaw := range result.([]interface{}) {
each := eachRaw.(map[string]interface{})
if each["_id"].(string) == _id {
m := toolkit.M{}
m, err = toolkit.ToM(each)
checkfatalerror(err)
config = m
isFound = true
}
}
if !isFound {
checkfatalerror(errors.New(fmt.Sprintf("config with _id %s is not found\n%#v", _id, result)))
}
case "map[string]interface {}":
m := toolkit.M{}
m, err = toolkit.ToM(result)
checkfatalerror(err)
config = m
default:
checkfatalerror(errors.New(fmt.Sprintf("invalid config file\n%#v", result)))
}
return
}
示例2: StopProcess
func StopProcess(datas []interface{}) (error, bool) {
var (
e error
isStopServ bool
)
for _, v := range datas {
vToMap, _ := toolkit.ToM(v)
if knot.SharedObject().Get(vToMap["nameid"].(string)) != nil {
e, isStopServ = StopService(knot.SharedObject().Get(vToMap["nameid"].(string)).(*sdt.GrabService))
if e != nil {
return e, false
}
} else {
return e, false
}
}
if !isStopServ {
isStopServ = true
} else {
isStopServ = false
}
return nil, isStopServ
}
示例3: StopService
func (w *WebGrabberController) StopService(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
w.PrepareHistoryPath()
payload := new(colonycore.WebGrabber)
err := r.GetPayload(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = colonycore.Get(payload, payload.ID)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
o, err := toolkit.ToM(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err, isRun := modules.StopProcess([]interface{}{o})
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(isRun, nil, "")
}
示例4: GetLog
func (w *WebGrabberController) GetLog(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
w.PrepareHistoryPath()
payload := struct {
ID string `json:"_id"`
Date string `json:"date"`
}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
wg := new(colonycore.WebGrabber)
err = colonycore.Get(wg, payload.ID)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
o, err := toolkit.ToM(wg)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
history := modules.NewHistory(payload.ID)
logs := history.GetLog([]interface{}{o}, payload.Date)
return helper.CreateResult(true, logs, "")
}
示例5: getresultobj
func getresultobj(strsplits []string, tval interface{}, val toolkit.M) interface{} {
var xval interface{}
if val == nil {
val = toolkit.M{}
}
switch {
case len(strsplits) == 1:
xval = tval
case len(strsplits) > 1:
tm := toolkit.M{}
if val.Has(strsplits[1]) {
tm, _ = toolkit.ToM(val[strsplits[1]])
}
xval = val.Set(strsplits[1], getresultobj(strsplits[1:], tval, tm))
}
return xval
// if {
// val = tval
// } else {
// val = val.Set(k, v)
// if val == nil {
// } else {
// }
// val = getresultobj(strsplits[1:], tval)
// }
// return val
}
示例6: Process
func Process(datas []interface{}) (error, bool) {
var (
e error
// isServRun bool
)
for _, v := range datas {
vToMap, e := toolkit.ToM(v)
if e != nil {
return e, false
}
if vToMap["sourcetype"].(string) == "SourceType_Http" {
grabs, e = GrabHtmlConfig(vToMap)
if e != nil {
return e, false
}
} else if vToMap["sourcetype"].(string) == "SourceType_DocExcel" {
grabs, e = GrabDocConfig(vToMap)
if e != nil {
return e, false
}
}
}
e, isServRun := StartService(grabs)
if e != nil {
return e, false
}
return nil, isServRun
}
示例7: foundCondition
func foundCondition(dataCheck toolkit.M, cond toolkit.M) bool {
resBool := true
for key, val := range cond {
if key == "$and" || key == "$or" {
for i, sVal := range val.([]interface{}) {
rVal := sVal.(map[string]interface{})
mVal := toolkit.M{}
for rKey, mapVal := range rVal {
mVal.Set(rKey, mapVal)
}
xResBool := foundCondition(dataCheck, mVal)
if key == "$and" {
resBool = resBool && xResBool
} else {
if i == 0 {
resBool = xResBool
} else {
resBool = resBool || xResBool
}
}
}
} else {
if reflect.ValueOf(val).Kind() == reflect.Map {
mVal := val.(map[string]interface{})
tomVal, _ := toolkit.ToM(mVal)
switch {
case tomVal.Has("$ne"):
if tomVal["$ne"].(string) == dataCheck.Get(key, "").(string) {
resBool = false
}
case tomVal.Has("$regex"):
resBool, _ = regexp.MatchString(tomVal["$regex"].(string), dataCheck.Get(key, "").(string))
case tomVal.Has("$gt"):
if tomVal["$gt"].(string) >= dataCheck.Get(key, "").(string) {
resBool = false
}
case tomVal.Has("$gte"):
if tomVal["$gte"].(string) > dataCheck.Get(key, "").(string) {
resBool = false
}
case tomVal.Has("$lt"):
if tomVal["$lt"].(string) <= dataCheck.Get(key, "").(string) {
resBool = false
}
case tomVal.Has("$lte"):
if tomVal["$lte"].(string) < dataCheck.Get(key, "").(string) {
resBool = false
}
}
} else if reflect.ValueOf(val).Kind() == reflect.String && val != dataCheck.Get(key, "").(string) {
resBool = false
}
}
}
return resBool
}
示例8: filterCondition
func filterCondition(cond toolkit.M) *dbox.Filter {
fb := new(dbox.Filter)
for key, val := range cond {
if key == "$and" || key == "$or" {
afb := []*dbox.Filter{}
for _, sVal := range val.([]interface{}) {
rVal := sVal.(map[string]interface{})
mVal := toolkit.M{}
for rKey, mapVal := range rVal {
mVal.Set(rKey, mapVal)
}
afb = append(afb, filterCondition(mVal))
}
if key == "$and" {
fb = dbox.And(afb...)
} else {
fb = dbox.Or(afb...)
}
} else {
if reflect.ValueOf(val).Kind() == reflect.Map {
mVal := val.(map[string]interface{})
tomVal, _ := toolkit.ToM(mVal)
switch {
case tomVal.Has("$eq"):
fb = dbox.Eq(key, tomVal["$eq"].(string))
case tomVal.Has("$ne"):
fb = dbox.Ne(key, tomVal["$ne"].(string))
case tomVal.Has("$regex"):
fb = dbox.Contains(key, tomVal["$regex"].(string))
case tomVal.Has("$gt"):
fb = dbox.Gt(key, tomVal["$gt"].(string))
case tomVal.Has("$gte"):
fb = dbox.Gte(key, tomVal["$gte"].(string))
case tomVal.Has("$lt"):
fb = dbox.Lt(key, tomVal["$lt"].(string))
case tomVal.Has("$lte"):
fb = dbox.Lte(key, tomVal["$lte"].(string))
}
} else {
fb = dbox.Eq(key, val)
}
}
}
return fb
}
示例9: Write
func (s *Server) Write(datakey DataKey, data []byte) error {
handleError := func(e error) error {
return errorlib.Error(packageName, modServer, "Write",
fmt.Sprintf("[%s.%s.%s] ", datakey.Owner, datakey.Cluster, datakey.Key)+e.Error())
}
if s.ServerType == ServerTypeMaster || s.ServerType == ServerTypeReplicaMaster {
dataSize := len(data)
snode, e := s.getNode(ServerTypeNode, dataSize)
if e != nil {
return handleError(e)
}
snodes := []*Server{snode}
srepma, e := s.getNode(ServerTypeReplicaMaster, dataSize)
if srepma != nil {
snodes = append(snodes, srepma)
}
for _, sn := range snodes {
mDataKey, e := toolkit.ToM(datakey)
if e != nil {
return handleError(e)
}
_, e = sn.call(opWrite, "GET", mDataKey, data)
if e != nil {
return handleError(e)
}
e = s.writeDataMap(datakey, dataSize, sn)
if e != nil {
return handleError(e)
}
}
} else {
key := datakey.BuildKey()
d := new(Data)
d.Key = key
d.Type = datakey.DataType
if datakey.Expiry == 0 {
d.Expiry = time.Now().Add(100 * 365 * 24 * 60 * time.Minute)
} else {
d.Expiry = time.Now().Add(time.Duration(datakey.Expiry))
}
d.Value = data
s.Items[key] = d
}
return nil
}
示例10: GetACLConnectionInfo
func (a *Login) GetACLConnectionInfo() (string, *dbox.ConnectionInfo) {
conf, err := toolkit.ToM(GetConfig(CONF_DB_ACL))
if err != nil {
return "", nil
}
ci := dbox.ConnectionInfo{
conf.GetString("host"),
conf.GetString("db"),
conf.GetString("user"),
conf.GetString("pass"),
toolkit.M{}.Set("timeout", 3),
}
return conf.GetString("driver"), &ci
}
示例11: GetLog
func (h *HistoryModule) GetLog(datas []interface{}, date string) interface{} {
for _, v := range datas {
vMap, _ := toolkit.ToM(v)
logConf := vMap["logconf"].(map[string]interface{})
dateNow := time.Now()
dateNowFormat := dateNow.Format(logConf["filepattern"].(string))
fileName := fmt.Sprintf("%s-%s", logConf["filename"], dateNowFormat)
h.logPath = f.Join(logConf["logpath"].(string), fileName)
}
file, err := os.Open(h.logPath)
if err != nil {
return err.Error()
}
defer file.Close()
getHours := strings.Split(date, ":")
containString := getHours[0] + ":" + getHours[1]
scanner := bufio.NewScanner(file)
lines := 0
containLines := 0
var logs []interface{}
for scanner.Scan() {
lines++
contains := strings.Contains(scanner.Text(), containString)
if contains {
containLines = lines
}
if lines == containLines {
logs = append(logs, "<li>"+scanner.Text()+"</li>")
}
}
if err := scanner.Err(); err != nil {
return err.Error()
}
var addSlice = toolkit.M{}
addSlice.Set("logs", logs)
return addSlice
}
示例12: TestConnection
func (d *DataSourceController) TestConnection(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())
}
driver := payload["Driver"].(string)
host := payload["Host"].(string)
database := payload["Database"].(string)
username := payload["UserName"].(string)
password := payload["Password"].(string)
var settings toolkit.M = nil
if settingsRaw := d.parseSettings(payload["Settings"], nil); settingsRaw != nil {
settings, err = toolkit.ToM(settingsRaw)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
}
if err := d.checkIfDriverIsSupported(driver); err != nil {
return helper.CreateResult(false, nil, err.Error())
}
fakeDataConn := &colonycore.Connection{
Database: database,
Driver: driver,
Host: host,
UserName: username,
Password: password,
Settings: settings,
}
err = helper.ConnectUsingDataConn(fakeDataConn).CheckIfConnected()
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, nil, "")
}
示例13: CheckStat
func (g *GrabModule) CheckStat(datas []interface{}) interface{} {
var (
grabStatus interface{}
lastDate, nextDate string
//toolkit.M
)
var summaryNotes = toolkit.M{} //map[string]interface{}{}
for _, v := range datas {
vToMap, e := toolkit.ToM(v)
if e != nil {
return e.Error()
}
if knot.SharedObject().Get(vToMap["nameid"].(string)) != nil {
i := knot.SharedObject().Get(vToMap["nameid"].(string)).(*sdt.GrabService)
tLast := cast.Date2String(i.LastGrabExe, "YYYY/MM/dd HH:mm:ss") //i.LastGrabExe.Format("2006/01/02 15:04:05")
if tLast != "0001/01/01 00:00:00" {
lastDate = tLast
}
tNext := cast.Date2String(i.NextGrabExe, "YYYY/MM/dd HH:mm:ss") //i.NextGrabExe.Format("2006/01/02 15:04:05")
if tNext != "0001/01/01 00:00:00" {
nextDate = tNext
}
startdate := cast.Date2String(i.StartDate, "YYYY/MM/dd HH:mm:ss") //i.StartDate.Format("2006/01/02 15:04:05")
enddate := cast.Date2String(i.EndDate, "YYYY/MM/dd HH:mm:ss") //i.EndDate.Format("2006/01/02 15:04:05")
summaryNotes.Set("startDate", startdate)
summaryNotes.Set("endDate", enddate)
summaryNotes.Set("grabCount", i.GrabCount)
summaryNotes.Set("rowGrabbed", i.RowGrabbed)
summaryNotes.Set("errorFound", i.ErrorFound)
grabStatus = ReadLog(vToMap["logconf"], i.ServiceRunningStat, i.Name, lastDate, nextDate, i.LastGrabStat, summaryNotes)
} else {
summaryNotes.Set("errorFound", 0)
grabStatus = ReadLog(vToMap["logconf"], false, vToMap["nameid"].(string), "", "", false, summaryNotes)
}
}
return grabStatus
}
示例14: GetChildMenu
func GetChildMenu(r *knot.WebContext, childMenu []colonycore.Menu) interface{} {
sessionId := r.Session("sessionid", "")
results := make([]toolkit.M, 0, 0)
for _, m := range childMenu {
result := toolkit.M{}
acc := acl.HasAccess(toolkit.ToString(sessionId), acl.IDTypeSession, m.AccessId, acl.AccessRead)
result, err := toolkit.ToM(m)
if err != nil {
fmt.Println(err)
}
if acc {
if len(m.Childrens) > 0 {
childs := GetChildMenu(r, m.Childrens)
result.Set("childrens", childs)
}
result.Set("detail", 7)
results = append(results, result)
}
}
return results
}
示例15: checkisonprocess
func checkisonprocess(id string, intervalconf toolkit.M, grabconf toolkit.M) (cond bool) {
cond = false
if _, f := mapsnapshot[id]; !f {
return
}
mtkdata := mapsnapshot[id]
mapcron, _ := toolkit.ToM(intervalconf["cronconf"])
if mtkdata.Grabstatus == "running" && len(mapcron) <= 0 {
cond = true
}
mtkstarttime := sedotan.StringToDate(mtkdata.Starttime)
timeoutint := toolkit.ToInt(grabconf.Get("timeout", 0), toolkit.RoundingAuto)
timeoutsec := time.Second * time.Duration(timeoutint)
if cond && (thistime.After(mtkstarttime.Add(timeoutsec)) && timeoutint > 0) {
cond = false
}
return
}