Esempio n. 1
0
func main() {
	b, err := gzipCompress([]byte("hello world"))
	utee.Chk(err)
	log.Println(string(b))
	rb, err := gunzip(b)
	utee.Chk(err)
	log.Println(string(rb))
}
Esempio n. 2
0
func main() {

	excelFileName := "/home/figo/develop/env/GOPATH/src/github.com/figoxu/goPraticse/files/excel/read/test.xlsx"
	xlFile, err := xlsx.OpenFile(excelFileName)
	utee.Chk(err)
	for _, sheet := range xlFile.Sheets {
		for _, row := range sheet.Rows {
			for _, cell := range row.Cells {
				s, err := cell.String()
				utee.Chk(err)
				fmt.Printf("%s\n", s)
			}
		}
	}
}
Esempio n. 3
0
func main() {
	rp = utee.CreateRedisPool(30, "106.75.27.144:6379", "baulk3?speed")
	con, err := mgo.Dial("mpush:[email protected]/mpush?maxPoolSize=50")
	utee.Chk(err)
	se = &MgoSe{
		referSession: con,
	}

	knameA := "figo_test"
	initSeq(knameA)
	nextSeq(knameA)
	initSeq(knameA)
	nextSeq(knameA)
	initSeq(knameA)
	nextSeq(knameA)
	nextSeq(knameA)
	nextSeq(knameA)

	knameB := "figo_testB"
	initSeq(knameB)
	nextSeq(knameB)
	initSeq(knameB)
	nextSeq(knameB)
	initSeq(knameB)
	nextSeq(knameB)
	nextSeq(knameB)
	nextSeq(knameB)
	nextSeq(knameB)

}
Esempio n. 4
0
func main() {
	ks_mpush, err := gocassa.ConnectToKeySpace("test", []string{"127.0.0.1"}, "", "")

	//	ks_mpush.Table()

	utee.Chk(err)
	ks_mpush.DebugMode(true)
	cache := ks_mpush.MapTable("cache", "Key", MCache{})
	cache.Create()

	figoC := &MCache{
		Key:   "figo",
		Value: "ok",
	}
	err = cache.Set(figoC).Run()
	if err != nil {
		log.Fatal(err)
	}

	tmp := &MCache{}
	err = cache.Read("figo", tmp).Run()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(tmp.Key, "---", tmp.Value)
}
Esempio n. 5
0
func (p *SimpleCache) Get(key string) bool {
	v, e := p.cache.Get([]byte(key))
	if freecache.ErrNotFound == e {
		return false
	}
	utee.Chk(e)
	return len(v) > 0 && v[0] == byte(1)
}
Esempio n. 6
0
func put(txt string, pool *redis.Pool) {
	c := pool.Get()
	defer c.Close()
	v := strings.Split(txt, " # ")
	id := v[0]
	pwd := v[1]
	mail := v[2]
	_, err := c.Do("HMSET", fmt.Sprint("account", id), "pwd", pwd, "mail", mail)
	utee.Chk(err)

}
Esempio n. 7
0
func connectAs(s string) *as.Client {
	h, port, err := utee.ParseUrl(s)
	utee.Chk(err)
	ac, err := as.NewClient(h, port)
	for err != nil {
		log.Println("as connect err:", err, " retry 2 sec later")

		time.Sleep(time.Second * time.Duration(2))
		ac, err = as.NewClient(h, port)
	}
	return ac
}
Esempio n. 8
0
func NewHealthGuards(port string) *HealthGuards {
	keyMe := ""
	ifaces, err := net.Interfaces()
	utee.Chk(err)
	for _, i := range ifaces {
		addrs, err := i.Addrs()
		utee.Chk(err)
		for _, addr := range addrs {
			var ip net.IP
			switch v := addr.(type) {
			case *net.IPNet:
				ip = v.IP
			case *net.IPAddr:
				ip = v.IP
			}
			ipStr := ip.String()
			if strings.Index(ipStr, "::") != -1 {
				continue
			}
			if ipStr == "127.0.0.1" {
				continue
			}
			if keyMe != "" {
				keyMe = fmt.Sprint(keyMe, ",")
			}
			keyMe = fmt.Sprint(keyMe, "http://", ipStr, port)
		}
	}
	healthGuard := &HealthGuards{
		m:     make(map[string]*HealthApi),
		keyMe: keyMe,
	}

	c := cron.New()
	c.AddFunc(cron_healthReport_task, healthGuard.healthReport)
	c.AddFunc(cron_healthChk_task, healthGuard.healthCheck)
	c.Start()
	return healthGuard
}
Esempio n. 9
0
func (p *HealthGuards) healthCheck() {
	c := rp.Get()
	defer c.Close()
	keys, err := redis.Strings(c.Do("HKEYS", "service_gateway"))
	utee.Chk(err)
	check := func(api string) bool {
		if b, err := utee.HttpGet(fmt.Sprint(api, "/api/health")); err == nil && string(b) == "ok" {
			return true
		}
		return false
	}
	for _, key := range keys {
		if key == p.keyMe {
			continue
		}
		if p.m[key] == nil {
			p.m[key] = &HealthApi{
				key:  key,
				apis: strings.Split(key, ","),
				api:  "",
			}
		}
		if check(p.m[key].api) {
			continue
		}
		healthFlag := false
		for _, api := range p.m[key].apis {
			log.Println("@api:", api)
			if b, err := utee.HttpGet(fmt.Sprint(api, "/api/health")); err == nil && string(b) == "ok" {
				healthFlag = true
				p.m[key].api = api
				break
			}
		}
		if !healthFlag {
			log.Println("[warn] @host:", key, " is not health . ")
			p.m[key].illCount++
		}
		if p.m[key].illCount > 3 {
			p.ill2die(key)
		}
	}

}
Esempio n. 10
0
func main() {
	vendors := []string{"*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**"}
	type S struct {
		Link     []string `json:"{{.link}}"`
		Mail     []string `json:"{{.mail}}"`
		Platform []string `json:"{{.platform}}"`
		Version  []string `json:"{{.version}}"`
		Update   []string `json:"{{.update}}"`
	}
	type M struct {
		To  []string `json:"to"`
		Sub S        `json:"sub"`
	}

	param := url.Values{
		"api_user":             {API_EMAIL_USER},
		"api_key":              {API_EMAIL_KEY},
		"from":                 {API_EMAIL_FROM},
		"fromname":             {API_EMAIL_FROMNAME},
		"subject":              {API_EMAIL_SUBJECT},
		"template_invoke_name": {API_EMAIL_TEMPLATE_NAME},
	}

	to := make([]string, 0)
	link := make([]string, 0)
	mail := make([]string, 0)
	platform := make([]string, 0)
	version := make([]string, 0)
	update := make([]string, 0)
	for i := 0; i < len(vendors); i++ {
		to = append(to, vendors[i])
		link = append(link, "http://doc.mpush.cn/sdk/ios/")
		mail = append(mail, vendors[i])
		platform = append(platform, "ios")
		version = append(version, "1.9.1")
		update = append(update, "优化SDK整体性能修复发现的问题")
		if len(to) < 2 && i <= len(vendors) {
			continue
		}
		m := &M{
			To: to,
			Sub: S{
				Link:     link,
				Mail:     mail,
				Platform: platform,
				Version:  version,
				Update:   update,
			},
		}
		msg, e := json.Marshal(m)
		utee.Chk(e)
		param.Set("substitution_vars", string(msg))
		log.Println("param", param)
		a, err := utee.HttpPost(API_EMAIL_URL, param)
		log.Print("a...", string(a))
		if err != nil {
			log.Println("send mail err", err)
		}
		to = nil
		link = nil
		mail = nil
		platform = nil
		version = nil
		update = nil
	}
}