Exemple #1
0
func (c *Conf) Md5Verify(data, sign string) error {
	if c.Md5Sign(data) == sign {
		return nil
	} else {
		return util.Err("md5 verify fail")
	}
}
Exemple #2
0
func RunFFCM_Cv(fcfg *util.Fcfg) error {
	if CLIENT != nil {
		return util.Err("client is running")
	}
	CLIENT = dtm.StartDTM_C(fcfg)
	CLIENT.AddProcH(NewVideoProc(CLIENT))
	return CLIENT.RunProcH()
}
Exemple #3
0
func (m *MockDb) Create() (interface{}, error) {
	if m.create > 0 && m.err {
		return nil, util.Err("error")
	}
	defer func() {
		m.create += 1
	}()
	switch m.create {
	case 0:
		return "db", nil
	case 1:
		return nil, util.Err("mock error")
	case 2:
		return nil, util.Err("mock error")
	default:
		return "new", nil
	}
}
Exemple #4
0
func (m *MockDb) Ping(db interface{}) error {
	if m.err {
		return util.Err("error")
	}
	defer func() {
		m.ping += 1
	}()
	switch m.ping {
	case 0:
		return nil
	case 1:
		return util.Err("error")
	case 2:
		return Closed
	default:
		return nil
	}
}
Exemple #5
0
func RunFFCM_S_V(fcfg *util.Fcfg) error {
	if SRV == nil {
		return util.Err("server is not running")
	}
	var listen = fcfg.Val("listen")
	SRV.Hand("", routing.Shared)
	routing.Shared.Print()
	log.D("listen web server on %v", listen)
	return routing.ListenAndServe(listen)
}
Exemple #6
0
func NextV(c *tmgo.Collection, id string, increase int64) (oldv int64, newv int64, err error) {
	var res = bson.M{}
	info, err := c.Find(bson.M{"_id": id}).Select(bson.M{"sequence": 1}).Apply(tmgo.Change{
		Update:    bson.M{"$inc": bson.M{"sequence": increase}},
		ReturnNew: true,
		Upsert:    true,
	}, &res)
	if err != nil {
		err = util.Err("require sequence(increase:%v) for %v fail, err:%v ", increase, id, err)
		return
	}
	if info.Updated != 1 && info.UpsertedId == nil {
		err = util.Err("require sequence(increase:%v) for %v fail, %v updated ", increase, id, info.Updated)
		return
	}
	newv = res["sequence"].(int64)
	oldv = newv - increase
	return
}
Exemple #7
0
func (c *Conf) Verify(data, sign, sign_type string) error {
	switch sign_type {
	case "MD5":
		return c.Md5Verify(data, sign)
	case "RSA":
		return c.AlipayVerify(data, sign)
	default:
		return util.Err("unkown verify sign type(%v)", sign_type)
	}
}
Exemple #8
0
func ChkIdx(C func(string) *tmgo.Collection, indexes map[string]map[string]tmgo.Index) error {
	for cname, index := range indexes {
		tc := C(cname)
		if _, err := tc.Count(); err != nil {
			return err
		}
		log.D("ChkIdx checking index on collection(%v)...", cname)
		idx_l, err := tc.Indexes()
		if err != nil {
			if qerr, ok := err.(*tmgo.QueryError); !ok || qerr.Code != 26 {
				err = util.Err("ChkIdx list indexes fail with error(%v) on collection(%v)", err, cname)
				log.E("%v", err)
				return err
			}
			log.D("ChkIdx the collection(%v) is not found, it will create empty one...", cname)
			err = tc.Create(&tmgo.CollectionInfo{})
			if err != nil {
				err = util.Err("ChkIdx create collection(%v) fail with error(%v)", cname, err)
				log.E("%v", err)
				return err
			}
		}
		exists := map[string]tmgo.Index{}
		for _, idx := range idx_l {
			exists[idx.Name] = idx
		}
		for iname, idx := range index {
			if _, ok := exists[iname]; ok {
				continue
			}
			idx.Name = iname
			err = C(cname).EnsureIndex(idx)
			if err != nil {
				err = util.Err("ChkIdx ensure index by keys(%v),name(%v) fail with error(%v) on collection(%v)", idx.Key, idx.Name, err, cname)
				log.E("%v", err)
				return err
			}
			log.D("ChkIdx ensure index(%v) on collection(%v) success", iname, cname)
		}
	}
	return nil
}
Exemple #9
0
func (c *Conf) Load(partner, seller, md5, private, publish, alipay string) error {
	c.Partner, c.Seller, c.MD5 = partner, seller, md5
	var err error
	//
	private_b, _ := pem.Decode([]byte(private))
	if private_b == nil {
		return util.Err("decode private key fail")
	}
	c.Private, err = x509.ParsePKCS1PrivateKey(private_b.Bytes)
	if err != nil {
		return err
	}
	//
	var tmp interface{}
	if len(publish) > 0 {
		publish_b, _ := pem.Decode([]byte(publish))
		if publish_b == nil {
			return util.Err("decode public key fail")
		}
		tmp, err = x509.ParsePKIXPublicKey(publish_b.Bytes)
		if err != nil {
			return err
		}
		c.Publish = tmp.(*rsa.PublicKey)
	}
	//
	//
	alipay_b, _ := pem.Decode([]byte(alipay))
	if alipay_b == nil {
		return util.Err("decode alipay key fail")
	}
	tmp, err = x509.ParsePKIXPublicKey(alipay_b.Bytes)
	if err != nil {
		return err
	}
	c.Alipay = tmp.(*rsa.PublicKey)
	return nil
}
Exemple #10
0
func (m *MGO_H) Create() (interface{}, error) {
	if len(m.Url) < 1 || len(m.Name) < 1 {
		return nil, util.Err("the database con/name is empty")
	}
	log.D("MGO_H start dail to %v", m)
	ss, err := tmgo.Dial(m.Url)
	if err == nil {
		log.D("MGO_H dail to %v success", m)
		return ss.DB(m.Name), nil
	}
	log.D("MGO_H dail to %v error->%v", m, err)
	if ss != nil {
		ss.Close()
	}
	return nil, err
}
Exemple #11
0
func (a *AbsV) Build(dtcm *dtm.DTCM_S, id, info interface{}, args ...interface{}) (interface{}, interface{}, []interface{}, error) {
	var src = fmt.Sprintf("%v", args[0])
	video, err := ParseVideo(filepath.Join(a.WDir, src))
	if err != nil {
		err = util.Err("AbsV parse video by src(%v) error->%v", src, err)
		log.E("%v", err)
		return nil, nil, nil, err
	}
	video.Info = info
	video.Alias = a.Alias
	var mv, _ = util.Json2Map(util.S2Json(video))
	var tw, th, dur = video.Width, video.Height, int64(video.Duration * 1000000)
	var dst interface{}
	if len(args) > 1 {
		dst = args[1]
	} else {
		dst = strings.TrimSuffix(src, filepath.Ext(src))
	}
	log.D("AbsV adding task by src(%v),width(%v),height(%v),duration(%v)", src, tw, th, dur)
	return id, mv, []interface{}{
		src, dst, tw, th, dur,
	}, nil
}