示例#1
0
func agentMarketMap() martini.Handler {
	marketMap := agent.MarketMap{}
	values, _ := csv.ReadCsvFile("./venders/serviceconfig/marketList.csv")
	for i := 0; i < len(values); i++ {
		rate, _ := strconv.ParseFloat(values[i][4], 64)
		marketMap[values[i][0]] = agent.Market{
			Id:    values[i][0],
			Name:  values[i][1],
			Code:  values[i][2],
			Agent: values[i][3],
			Rate:  rate,
		}
	}
	return func(c martini.Context) {
		c.MapTo(&marketMap, (*agent.MarketRepo)(nil))
	}
}
示例#2
0
func main() {

	pool := &redis.Pool{
		MaxIdle:     10,
		IdleTimeout: 600 * time.Second,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", "127.0.0.1:6379")
			if err != nil {
				panic(err)
				return nil, err
			}

			return c, nil
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}

	conn := pool.Get()

	values, err := csv.ReadCsvFile("./venders/serviceconfig/marketList.csv")
	fmt.Print(err)
	marketArray := []agent.Market{}
	fmt.Print("superwolf")
	fmt.Print(values)
	for i := 0; i < len(values); i++ {
		rate, _ := strconv.ParseFloat(values[i][4], 64)
		market := agent.Market{
			Id:    values[i][0],
			Name:  values[i][1],
			Code:  values[i][2],
			Agent: values[i][3],
			Rate:  rate,
		}
		marketArray = append(marketArray, market)
		jsonString, _ := json.Marshal(market)
		fmt.Println(string(jsonString))
		_, err := conn.Do("hset", "superwolf", market.Id, jsonString)

		fmt.Print(err)
	}

}