示例#1
0
文件: static.go 项目: jango2015/wk
func newFileCache(root string) (*fileCache, error) {
	if info, err := os.Stat(root); err != nil {
		return nil, err
	} else if !info.IsDir() {
		return nil, fmt.Errorf("%s isn't a directory", root)
	}

	fc := &fileCache{
		root:   root,
		cache:  mcache.NewMCache(),
		expire: 60,
	}
	if fw, err := fsw.NewFsWatcher(root); err == nil {
		fc.watcher = fw
		fc.watcher.Listen(fc.notify)
	}
	return fc, nil
}
示例#2
0
func init() {
	flag.Usage = func() {
		log.Printf("Usage: urlmapper [flags]")
		flag.PrintDefaults()
		os.Exit(2)
	}
	flag.Parse()

	Cache = mcache.NewMCache()

	hostsMap = map[string]string{
		"ua.tribuna.com" + *hPort:  "ua",
		"tribuna.com" + *hPort:     "ua",
		"www.tribuna.com" + *hPort: "ua",
		"www.sports.ru" + *hPort:   "ru",
	}

	if len(*urlMapFile) > 0 {
		go readUrlMapFileWorker(*urlMapFile)
	}

	if *redisEnabled {
		Pool = &redis.Pool{
			MaxActive:   1000,
			MaxIdle:     3,
			IdleTimeout: 240 * time.Second,
			Dial: func() (redis.Conn, error) {
				d, _ := time.ParseDuration("250ms")
				c, err := redis.DialTimeout("tcp", *redisServer, d, d, d)
				if err != nil {
					log.Println("Redis: connection error")
					return nil, err
				}
				return c, err
			},
			TestOnBorrow: func(c redis.Conn, t time.Time) error {
				_, err := c.Do("PING")
				return err
			},
		}
	}
}
示例#3
0
func init() {
	flag.Usage = func() {
		log.Printf("Usage: urlmapper [flags]")
		flag.PrintDefaults()
		os.Exit(2)
	}
	flag.Parse()

	Cache = mcache.NewMCache()

	hostsMap = map[string]string{
		"ua.tribuna.com" + *hPort:  "ua",
		"tribuna.com" + *hPort:     "ua",
		"www.tribuna.com" + *hPort: "ua",
		"www.sports.ru" + *hPort:   "ru",
	}

	if len(*urlMapFile) > 0 {
		go readUrlMapFileWorker(*urlMapFile)
	}
}
示例#4
0
文件: default.go 项目: jango2015/wk
func newMCache() *MCache {
	return &MCache{
		cache: mcache.NewMCache(),
	}
}