本文整理匯總了Golang中github.com/eaciit/toolkit.ToInt函數的典型用法代碼示例。如果您正苦於以下問題:Golang ToInt函數的具體用法?Golang ToInt怎麽用?Golang ToInt使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ToInt函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetSession
func (a *SessionController) GetSession(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)
}
tSession := new(acl.Session)
if find := toolkit.ToString(payload["find"]); find != "" {
filter = new(dbox.Filter)
filter = dbox.Contains("loginid", find)
}
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))
// c, err := acl.Find(tSession, nil, toolkit.M{}.Set("take", payload["take"].(int)).Set("skip", payload["skip"].(int)))
c, err := acl.Find(tSession, 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)
for i, val := range arrm {
arrm[i].Set("duration", time.Since(val["created"].(time.Time)).Hours())
arrm[i].Set("status", "ACTIVE")
if val["expired"].(time.Time).Before(time.Now().UTC()) {
arrm[i].Set("duration", val["expired"].(time.Time).Sub(val["created"].(time.Time)).Hours())
arrm[i].Set("status", "EXPIRED")
}
}
c.Close()
c, err = acl.Find(tSession, 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, "")
}
}
示例2: TestAggr
func TestAggr(t *testing.T) {
skipIfNil(t)
c2 := c.Min(fn).Max(fn).Sum(fn).Avg(fn).Exec()
check(t, c2.Error, "Aggr")
if toolkit.ToInt(c2.Result.Min, toolkit.RoundingAuto) != min ||
toolkit.ToInt(c2.Result.Max, toolkit.RoundingAuto) != max ||
c2.Result.Sum != toolkit.ToFloat64(sum, 4, toolkit.RoundingAuto) ||
c2.Result.Avg != avg {
t.Fatalf("Error aggr. Got %v\n", toolkit.JsonString(c2.Result))
}
toolkit.Println("Value: ", toolkit.JsonString(c2.Result))
}
示例3: 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, "")
}
}
示例4: 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, "")
}
}
示例5: KendoGridSettings
func (a *Controller) KendoGridSettings(ins toolkit.M) toolkit.M {
if ins == nil {
ins = toolkit.M{}
}
s := toolkit.M{}
q_skip := a.Ctx.Input.Query("skip")
q_page := a.Ctx.Input.Query("page")
q_size := a.Ctx.Input.Query("pageSize")
if q_skip != "" {
s.Set("skip", toolkit.ToInt(q_skip))
}
if q_page != "" {
s.Set("page", toolkit.ToInt(q_page))
}
if q_size != "" {
s.Set("limit", toolkit.ToInt(q_size))
}
sortField := strings.ToLower(a.Ctx.Input.Query("sort[0][field]"))
sortDir := a.Ctx.Input.Query("sort[0][dir]")
if sortField != "" {
if sortField == "id" {
sortField = "_id"
}
if sortDir == "" || sortDir == "asc" {
s.Set("order", []string{sortField})
} else {
s.Set("order", []string{"-" + sortField})
}
}
if fqe := a.KendoGridFilter("filter"); fqe != nil {
if ins.Has("where") {
fqe = dbs.And(fqe, ins.Get("where").(*dbs.QE))
}
s.Set("where", fqe)
}
return s
}
示例6: 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, "")
}
示例7: ToString
func ToString(reflectIs reflect.Kind, i interface{}) string {
var s string
if reflectIs != reflect.String {
toI := toolkit.ToInt(i)
s = strconv.Itoa(toI)
} else {
s = i.(string)
}
return s
}
示例8: toInterface
func toInterface(data string, dataType string, dateFormat string) interface{} {
if dataType == "" {
if strings.HasPrefix(data, "#") && strings.HasSuffix(data, "#") {
dataType = DataDate
} else {
vfloat := toolkit.ToFloat64(dataType, 2, toolkit.RoundingAuto)
vint := toolkit.ToInt(dataType, toolkit.RoundingAuto)
if int(vfloat) == vint && vint != 0 {
dataType = DataInt
} else if vfloat != 0 {
// dataType = DataFloat
b, i := toolkit.MemberIndex(DataFloats, dataType)
if b {
for idx, dataFloat := range DataFloats {
if idx == i {
dataType = dataFloat
}
}
}
} else {
dataType = DataString
}
}
}
if dataType == DataDate {
return toolkit.String2Date(data, dateFormat)
} else if dataType == DataInt {
return toolkit.ToInt(data, toolkit.RoundingAuto)
} else if toolkit.HasMember(DataFloats, dataType) {
return toolkit.ToFloat64(data, 2, toolkit.RoundingAuto)
} else {
return data
}
return nil
}
示例9: 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
}
示例10: checkistimerun
//Check Time run and record to snapshot
func checkistimerun(id string, intervalconf toolkit.M, grabconf toolkit.M) (cond bool) {
cond = false
var mtklaststarttime, mtklastupdate time.Time
tempss := Snapshot{Id: id,
Starttime: "",
Laststartgrab: "",
Lastupdate: "",
Grabcount: 1,
Rowgrabbed: 0,
Errorfound: 0,
Lastgrabstatus: "",
Grabstatus: "running",
Cgtotal: 0,
Cgprocess: 0,
Note: "",
Pid: 0}
// Lastgrabstatus string //[success|failed]
// Grabstatus string //[running|done]
strintervalconf := intervalconf.Get("starttime", "").(string)
intervalstart := sedotan.StringToDate(strintervalconf)
strintervaltype := intervalconf.Get("intervaltype", "").(string)
grabinterval := toolkit.ToInt(intervalconf.Get("grabinterval", 0), toolkit.RoundingAuto)
mtkdata := Snapshot{}
if _, f := mapsnapshot[id]; f {
mtkdata = mapsnapshot[id]
tempss.Starttime = mtkdata.Starttime
//for data timeout
mtklaststarttime = sedotan.StringToDate(mtkdata.Laststartgrab)
mtklastupdate = sedotan.StringToDate(mtkdata.Lastupdate)
timeoutint := toolkit.ToInt(grabconf.Get("timeout", 0), toolkit.RoundingAuto)
timeoutsec := time.Second * time.Duration(timeoutint)
if mtkdata.Grabstatus == "running" && thistime.After(mtklaststarttime.Add(timeoutsec)) && timeoutint > 0 {
mtkdata.Lastupdate = sedotan.DateToString(mtklaststarttime.Add(timeoutsec))
mtklastupdate = sedotan.StringToDate(mtkdata.Lastupdate)
mtkdata.Lastgrabstatus = "failed"
mtkdata.Grabstatus = "done"
}
// set initial - found a long time ago snapshot
if intervalstart.After(sedotan.StringToDate(mtkdata.Starttime)) {
tempss.Starttime = sedotan.DateToString(thistime)
mtkdata.Grabcount = 0
mtkdata.Rowgrabbed = 0
mtkdata.Errorfound = 0
mtkdata.Lastgrabstatus = ""
}
}
if mtkdata.Lastgrabstatus == "failed" {
grabinterval = toolkit.ToInt(intervalconf.Get("timeoutinterval", 0), toolkit.RoundingAuto)
}
if strintervalconf != "" && intervalstart.Before(thistime) {
_, fcond := mapsnapshot[id]
switch {
case !fcond || intervalstart.After(sedotan.StringToDate(mtkdata.Starttime)):
cond = true
case intervalconf.Get("grabinterval", 0).(float64) > 0:
var durationgrab time.Duration
switch strintervaltype {
case "seconds":
durationgrab = time.Second * time.Duration(grabinterval)
case "minutes":
durationgrab = time.Minute * time.Duration(grabinterval)
case "hours":
durationgrab = time.Hour * time.Duration(grabinterval)
}
nextgrab := mtklastupdate.Add(durationgrab)
if nextgrab.Before(thistime) && !mtklastupdate.IsZero() {
cond = true
tempss.Grabcount = mtkdata.Grabcount + 1
tempss.Rowgrabbed = mtkdata.Rowgrabbed
tempss.Errorfound = mtkdata.Errorfound
tempss.Lastgrabstatus = mtkdata.Lastgrabstatus
}
}
}
mapcronconf, _ := toolkit.ToM(intervalconf.Get("cronconf", nil))
minutetime := sedotan.DateMinutePress(thistime) //review this and the usage and parsing in cron
if len(mapcronconf) > 0 {
//min hour dayofmonth month dayofweek
cond = true
arrstr := [6]string{"min", "hour", "dayofmonth", "month", "dayofweek"}
// arrstr := [6]string{"month", "dayofmonth", "dayofweek", "hour", "min", "second"}
for _, str := range arrstr {
sval := toolkit.ToString(mapcronconf.Get(str, ""))
ival := toolkit.ToInt(sval, toolkit.RoundingAuto)
var valcom int
switch str {
//.........這裏部分代碼省略.........
示例11: TestQuery
func (d *DataBrowserController) TestQuery(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
data := colonycore.DataBrowser{} //map[string]interface{}{}
err := r.GetPayload(&data)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
conn, datacon, err := d.connToDatabase(data.ConnectionID)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
query, err := d.parseQuery(conn, data, datacon)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
cursor, err := query.Cursor(nil)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
dataFetch := []toolkit.M{}
err = cursor.Fetch(&dataFetch, 1, false)
if err != nil {
cursor.ResetFetch()
err = cursor.Fetch(&dataFetch, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
}
metadata := []*colonycore.StructInfo{}
// var dt string
for i, dataFields := range dataFetch {
if i > 0 {
break
}
j := 1
for keyField, dataField := range dataFields {
if strings.Contains(keyField, "id") && !strings.Contains(data.QueryText, "id") &&
!strings.Contains(data.QueryText, "*") && data.TableNames == "" {
continue
}
sInfo := &colonycore.StructInfo{}
sInfo.Field = keyField
sInfo.Label = keyField
rf := "string"
if dataField != nil {
rf = toolkit.TypeName(dataField)
if rf == "time.Time" {
rf = "date"
}
}
sInfo.DataType = rf
sInfo.Format = ""
sInfo.Align = "Left"
sInfo.ShowIndex = toolkit.ToInt(j, toolkit.RoundingAuto)
sInfo.Sortable = false
sInfo.SimpleFilter = false
sInfo.AdvanceFilter = false
sInfo.Aggregate = ""
metadata = append(metadata, sInfo)
j++
}
}
data.MetaData = metadata
return helper.CreateResult(true, data, "")
}
示例12: GrabHtmlConfig
func GrabHtmlConfig(data toolkit.M) (*sdt.GrabService, error) {
var e error
var gi, ti time.Duration
xGrabService := sdt.NewGrabService()
xGrabService.Name = data["nameid"].(string) //"irondcecom"
xGrabService.Url = data["url"].(string) //"http://www.dce.com.cn/PublicWeb/MainServlet"
xGrabService.SourceType = sdt.SourceType_HttpHtml
grabintervalToInt := toolkit.ToInt(data["grabinterval"], toolkit.RoundingAuto)
timeintervalToInt := toolkit.ToInt(data["timeoutinterval"], toolkit.RoundingAuto)
if data["intervaltype"].(string) == "seconds" {
gi = time.Duration(grabintervalToInt) * time.Second
ti = time.Duration(timeintervalToInt) * time.Second
} else if data["intervaltype"].(string) == "minutes" {
gi = time.Duration(grabintervalToInt) * time.Minute
ti = time.Duration(timeintervalToInt) * time.Minute
} else if data["intervaltype"].(string) == "hours" {
gi = time.Duration(grabintervalToInt) * time.Hour
ti = time.Duration(timeintervalToInt) * time.Hour
}
xGrabService.GrabInterval = gi //* time.Minute
xGrabService.TimeOutInterval = ti //* time.Minute //time.Hour, time.Minute, time.Second
xGrabService.TimeOutIntervalInfo = fmt.Sprintf("%v %s", timeintervalToInt, data["intervaltype"] /*"seconds"*/)
grabConfig := sdt.Config{}
if data["calltype"].(string) == "POST" {
dataurl := toolkit.M{}
for _, grabconf := range data["grabconf"].(map[string]interface{}) {
grabDataConf, e := toolkit.ToM(grabconf)
if e != nil {
return nil, e
}
for key, subGrabDataConf := range grabDataConf {
if reflect.ValueOf(subGrabDataConf).Kind() == reflect.Float64 {
i := toolkit.ToInt(subGrabDataConf, toolkit.RoundingAuto)
toString := strconv.Itoa(i)
dataurl[key] = toString
} else {
dataurl[key] = subGrabDataConf
}
}
}
grabConfig.SetFormValues(dataurl)
}
grabDataConf, e := toolkit.ToM(data["grabconf"])
if e != nil {
return nil, e
}
isAuthType := grabDataConf.Has("authtype")
if isAuthType {
grabConfig.AuthType = grabDataConf["authtype"].(string)
grabConfig.LoginUrl = grabDataConf["loginurl"].(string) //"http://localhost:8000/login"
grabConfig.LogoutUrl = grabDataConf["logouturl"].(string) //"http://localhost:8000/logout"
grabConfig.LoginValues = toolkit.M{}.
Set("name", grabDataConf["loginvalues"].(map[string]interface{})["name"].(string)).
Set("password", grabDataConf["loginvalues"].(map[string]interface{})["password"].(string))
}
xGrabService.ServGrabber = sdt.NewGrabber(xGrabService.Url, data["calltype"].(string), &grabConfig)
logconfToMap, e := toolkit.ToM(data["logconf"])
if e != nil {
return nil, e
}
logpath := logconfToMap["logpath"].(string) //"E:\\data\\vale\\log"
filename := logconfToMap["filename"].(string) + "-%s" //"LOG-GRABDCETEST"
filepattern := logconfToMap["filepattern"].(string) //"20060102"
logconf, e := toolkit.NewLog(false, true, logpath, filename, filepattern)
if e != nil {
return nil, e
}
xGrabService.Log = logconf
xGrabService.ServGrabber.DataSettings = make(map[string]*sdt.DataSetting)
xGrabService.DestDbox = make(map[string]*sdt.DestInfo)
tempDataSetting := sdt.DataSetting{}
tempDestInfo := sdt.DestInfo{}
// isCondition := []interface{}{}
tempFilterCond := toolkit.M{}
// var condition string
for _, dataSet := range data["datasettings"].([]interface{}) {
dataToMap, _ := toolkit.ToM(dataSet)
tempDataSetting.RowSelector = dataToMap["rowselector"].(string)
for _, columnSet := range dataToMap["columnsettings"].([]interface{}) {
columnToMap, e := toolkit.ToM(columnSet)
if e != nil {
//.........這裏部分代碼省略.........
示例13: fetchConfig
//.........這裏部分代碼省略.........
if err != nil {
Log.AddLog(fmt.Sprintf("[Fetch.Ds.%d] Found : %v", i, err.Error()), "ERROR")
continue
}
tnameid := toolkit.ToString(mVal.Get("nameid", ""))
if tnameid == "" {
Log.AddLog(fmt.Sprintf("[Fetch.Ds.%d] Data Setting Id is not found", i), "ERROR")
continue
}
tDataSetting.RowSelector = toolkit.ToString(mVal.Get("rowselector", ""))
// Fetch columnsettings
if !mVal.Has("columnsettings") || !(toolkit.TypeName(mVal["columnsettings"]) == "[]interface {}") {
Log.AddLog(fmt.Sprintf("[Fetch.Ds.%d.%v] Found : columnsettings is not found or incorrect", i, tnameid), "ERROR")
continue
}
tDataSetting.ColumnSettings = make([]*sedotan.GrabColumn, 0, 0)
for xi, Valcs := range mVal["columnsettings"].([]interface{}) {
mValcs := toolkit.M{}
mValcs, err = toolkit.ToM(Valcs)
if err != nil {
Log.AddLog(fmt.Sprintf("[Fetch.Ds.%d.%v.%v] Found : columnsettings is not found or incorrect", i, tnameid, xi), "ERROR")
continue
}
tgrabcolumn := sedotan.GrabColumn{}
tgrabcolumn.Alias = toolkit.ToString(mValcs.Get("alias", ""))
tgrabcolumn.Selector = toolkit.ToString(mValcs.Get("selector", ""))
tgrabcolumn.ValueType = toolkit.ToString(mValcs.Get("valuetype", ""))
tgrabcolumn.AttrName = toolkit.ToString(mValcs.Get("attrname", ""))
tindex := toolkit.ToInt(mValcs.Get("index", 0), toolkit.RoundingAuto)
tDataSetting.Column(tindex, &tgrabcolumn)
}
//Fetch Filter Condition
if mVal.Has("filtercond") {
tfiltercond := toolkit.M{}
tfiltercond, err = toolkit.ToM(mVal.Get("filtercond", toolkit.M{}))
if err != nil {
Log.AddLog(fmt.Sprintf("[Fetch.Ds.%d.%v] Found : filter cond is incorrect, %v", i, tnameid, err.Error()), "ERROR")
} else {
tDataSetting.SetFilterCond(tfiltercond)
}
}
//Fetch Connection Info
tConnInfo := toolkit.M{}
tConnInfo, err = toolkit.ToM(mVal.Get("connectioninfo", toolkit.M{}))
if err != nil {
Log.AddLog(fmt.Sprintf("[Fetch.Ds.%d.%v] Found : %v", i, tnameid, err.Error()), "ERROR")
continue
}
tDestDbox.desttype = toolkit.ToString(mVal.Get("desttype", ""))
tDestDbox.collection = toolkit.ToString(tConnInfo.Get("collection", ""))
tHost := toolkit.ToString(tConnInfo.Get("host", ""))
tDatabase := toolkit.ToString(tConnInfo.Get("database", ""))
tUserName := toolkit.ToString(tConnInfo.Get("username", ""))
tPassword := toolkit.ToString(tConnInfo.Get("password", ""))
tSettings := toolkit.M{}
tSettings, err = toolkit.ToM(tConnInfo.Get("settings", nil))
if err != nil {
Log.AddLog(fmt.Sprintf("[Fetch.Ds.%d.%v] Connection Setting Found : %v", i, tnameid, err.Error()), "ERROR")
示例14: constructActions
func constructActions(list []interface{}) (flows []colonycore.FlowAction) {
for _, act := range list {
flowAction := act.(map[string]interface{})
server := colonycore.Server{}
if flowAction["server"] != nil {
dsServer := []colonycore.Server{}
cursor, err := colonycore.Find(new(colonycore.Server), dbox.Eq("_id", tk.ToString(flowAction["server"])))
if err != nil {
//
} else {
if cursor != nil {
cursor.Fetch(&dsServer, 0, false)
defer cursor.Close()
}
if len(dsServer) > 0 {
server = dsServer[0]
}
}
}
inputParam := tk.M{}
outputParam := tk.M{}
outputType := ""
for _, in := range flowAction["inputparam"].([]interface{}) {
inputParam.Set("", in)
}
if flowAction["outputtype"] != nil {
outputType = tk.ToString(flowAction["outputtype"])
}
for _, out := range flowAction["outputparam"].([]interface{}) {
outputParam.Set("", out)
}
OK := []string{}
KO := []string{}
for _, str := range flowAction["OK"].([]interface{}) {
OK = append(OK, tk.ToString(str))
}
for _, str := range flowAction["KO"].([]interface{}) {
KO = append(KO, tk.ToString(str))
}
actionType := tk.ToString(flowAction["type"])
flow := colonycore.FlowAction{
Id: tk.ToString(flowAction["id"]),
Name: tk.ToString(flowAction["name"]) + "-" + tk.ToString(flowAction["id"]),
Description: tk.ToString(flowAction["description"]),
Type: actionType,
Server: server,
OK: OK,
KO: KO,
Retry: tk.ToInt(flowAction["Retry"], ""),
Interval: tk.ToInt(flowAction["Interval"], ""),
FirstAction: flowAction["firstaction"].(bool),
InputParam: inputParam,
OutputParam: outputParam,
OutputType: outputType,
OutputPath: "",
}
dataAction := flowAction["action"].(map[string]interface{})
switch actionType {
case dataflow.ACTION_TYPE_SPARK:
spark := colonycore.ActionSpark{
Master: tk.ToString(dataAction["master"]),
Mode: tk.ToString(dataAction["mode"]),
File: tk.ToString(dataAction["appfiles"]),
MainClass: tk.ToString(dataAction["mainclass"]),
Args: tk.ToString(dataAction["args"]),
}
flow.Action = spark
break
case dataflow.ACTION_TYPE_HIVE:
hive := colonycore.ActionHive{
ScriptPath: tk.ToString(dataAction),
// Params: ,
}
flow.Action = hive
break
case dataflow.ACTION_TYPE_SSH:
ssh := colonycore.ActionSSH{
Command: tk.ToString(dataAction["script"]),
}
flow.Action = ssh
break
case dataflow.ACTION_TYPE_HDFS:
hdfs := colonycore.ActionHDFS{
Command: tk.ToString(dataAction["script"]),
}
flow.Action = hdfs
break
//.........這裏部分代碼省略.........
示例15: GrabDocConfig
func GrabDocConfig(data toolkit.M) (*sdt.GrabService, error) {
var e error
var gi, ti time.Duration
GrabService := sdt.NewGrabService()
GrabService.Name = data["nameid"].(string) //"iopriceindices"
GrabService.SourceType = sdt.SourceType_DocExcel
grabintervalToInt := toolkit.ToInt(data["grabinterval"], toolkit.RoundingAuto)
timeintervalToInt := toolkit.ToInt(data["timeoutinterval"], toolkit.RoundingAuto)
if data["intervaltype"].(string) == "seconds" {
gi = time.Duration(grabintervalToInt) * time.Second
ti = time.Duration(timeintervalToInt) * time.Second
} else if data["intervaltype"].(string) == "minutes" {
gi = time.Duration(grabintervalToInt) * time.Minute
ti = time.Duration(timeintervalToInt) * time.Minute
} else if data["intervaltype"].(string) == "hours" {
gi = time.Duration(grabintervalToInt) * time.Hour
ti = time.Duration(timeintervalToInt) * time.Hour
}
GrabService.GrabInterval = gi
GrabService.TimeOutInterval = ti //time.Hour, time.Minute, time.Second
GrabService.TimeOutIntervalInfo = fmt.Sprintf("%v %s", timeintervalToInt, data["intervaltype"])
ci := dbox.ConnectionInfo{}
grabDataConf, e := toolkit.ToM(data["grabconf"])
if e != nil {
return nil, e
}
isDoctype := grabDataConf.Has("doctype")
if isDoctype {
connToMap, e := toolkit.ToM(grabDataConf["connectioninfo"])
if e != nil {
return nil, e
}
ci.Host = connToMap["host"].(string) //"E:\\data\\sample\\IO Price Indices.xlsm"
if hasSettings := connToMap.Has("settings"); !hasSettings {
ci.Settings = nil
} else {
settingToMap, e := toolkit.ToM(connToMap["settings"])
if e != nil {
return nil, e
}
ci.Settings = settingToMap //toolkit.M{}.Set("useheader", settingToMap["useheader"].(bool)).Set("delimiter", settingToMap["delimiter"])
}
GrabService.ServGetData, e = sdt.NewGetDatabase(ci.Host, grabDataConf["doctype"].(string), &ci)
}
logconfToMap, e := toolkit.ToM(data["logconf"])
if e != nil {
return nil, e
}
logpath := logconfToMap["logpath"].(string) //"E:\\data\\vale\\log"
filename := logconfToMap["filename"].(string) + "-%s" //"LOG-LOCALXLSX-%s"
filepattern := logconfToMap["filepattern"].(string) //"20060102"
logconf, e := toolkit.NewLog(false, true, logpath, filename, filepattern)
if e != nil {
return nil, e
}
GrabService.Log = logconf
GrabService.ServGetData.CollectionSettings = make(map[string]*sdt.CollectionSetting)
GrabService.DestDbox = make(map[string]*sdt.DestInfo)
tempDataSetting := sdt.CollectionSetting{}
tempDestInfo := sdt.DestInfo{}
for _, dataSet := range data["datasettings"].([]interface{}) {
dataToMap, e := toolkit.ToM(dataSet)
if e != nil {
return nil, e
}
tempDataSetting.Collection = dataToMap["rowselector"].(string) //"HIST"
for _, columnSet := range dataToMap["columnsettings"].([]interface{}) {
columnToMap, e := toolkit.ToM(columnSet)
if e != nil {
return nil, e
}
tempDataSetting.SelectColumn = append(tempDataSetting.SelectColumn, &sdt.GrabColumn{Alias: columnToMap["alias"].(string), Selector: columnToMap["selector"].(string)})
}
GrabService.ServGetData.CollectionSettings[dataToMap["name"].(string)] = &tempDataSetting //DATA01 use name in datasettings
// fmt.Println("doctype>", grabDataConf["doctype"])
connToMap, e := toolkit.ToM(dataToMap["connectioninfo"])
if e != nil {
return nil, e
}
var db, usr, pwd string
if hasDb := connToMap.Has("database"); !hasDb {
db = ""
} else {
db = connToMap["database"].(string)
}
if hasUser := connToMap.Has("username"); !hasUser {
usr = ""
} else {
//.........這裏部分代碼省略.........