Beispiel #1
0
func strToRawMessage(str string) (res json.RawMessage) {
	err := json.Unmarshal([]byte(str), &res)
	if err != nil {
		panic(err)
	}
	return
}
Beispiel #2
0
func (cp *ClusterConfigPlugin) Configure(cfg json.RawMessage) error {
	err := json.Unmarshal(cfg, &cp.clusterPluginCfg)
	if err != nil {
		return err
	}
	return err
}
Beispiel #3
0
func (self *GraphitePlugin) Configure(cfg json.RawMessage) error {
	err := json.Unmarshal(cfg, &self.cfg)
	if err != nil {
		return err
	}
	return err
}
Beispiel #4
0
func (self *CacheProxyPlugin) Configure(cfg json.RawMessage) error {
	// Parse config
	err := json.Unmarshal(cfg, &self.config)
	if err != nil {
		return err
	}

	// Configure backends
	for _, pConf := range self.config.Backends {
		if plug, err := plugins.DefaultPluginStore.Create(pConf.Plugin, pConf.PluginConfig); err == nil {
			if cPlug, correctPlug := plug.(gopnik.CachePluginInterface); correctPlug {
				self.backends = append(self.backends, cacheProxyPluginBackend{
					Name:     pConf.Plugin,
					Plugin:   cPlug,
					MinZoom:  pConf.MinZoom,
					MaxZoom:  pConf.MaxZoom,
					Tags:     pConf.Tags,
					ReadOnly: pConf.ReadOnly,
				})
			} else {
				return fmt.Errorf("Plugin '%s' is not CachePluginInterface", pConf.Plugin)
			}
		} else {
			return fmt.Errorf("Plugin '%s' not configured: '%v'", pConf.Plugin, err)
		}
	}

	return nil
}
Beispiel #5
0
func (f *FakePluginFactory) New(cfg json.RawMessage) (interface{}, error) {
	res := new(FakePlugin)
	err := json.Unmarshal(cfg, res)
	if err != nil {
		return nil, err
	}
	return res, nil
}
Beispiel #6
0
func (self *BBoxTagFilterPlugin) Configure(cfg json.RawMessage) error {
	var config bBoxTagFilterPluginConfig
	err := json.Unmarshal(cfg, &config)
	if err != nil {
		return err
	}
	self.rules = config.Rules
	return nil
}
Beispiel #7
0
func (self *TileUrlPlugin) Configure(cfg json.RawMessage) error {
	config := tileUrlPluginConf{}

	err := json.Unmarshal(cfg, &config)
	if err != nil {
		return err
	}

	self.url = config.Url

	return nil
}
Beispiel #8
0
func IntiLog(rawCfg json.RawMessage) error {
	cfg := new(logConfig)
	err := json.Unmarshal(rawCfg, cfg)
	if err != nil {
		return err
	}

	if initializer, found := logBackendMap[cfg.Backend]; found {
		if err = initializer(cfg); err != nil {
			return err
		}
	} else {
		return err
	}

	switch cfg.Level {
	case "Critical":
		logging.SetLevel(logging.CRITICAL, "global")
	case "Error":
		logging.SetLevel(logging.ERROR, "global")
	case "Warning":
		logging.SetLevel(logging.WARNING, "global")
	case "Notice":
		logging.SetLevel(logging.NOTICE, "global")
	case "Info":
		logging.SetLevel(logging.INFO, "global")
	case "Debug":
		logging.SetLevel(logging.DEBUG, "global")
	default:
		return fmt.Errorf("Invalid log level '%s'", cfg.Level)
	}

	if cfg.Format == "" {
		cfg.Format = "[%{level}] %{message}"
	}

	formatter, err := logging.NewStringFormatter(cfg.Format)
	if err != nil {
		return err
	}
	logging.SetFormatter(formatter)

	return nil
}
Beispiel #9
0
func (self *KVStorePlugin) Configure(cfg json.RawMessage) error {
	err := json.Unmarshal(cfg, &self.config)
	if err != nil {
		return err
	}

	plug, err := plugins.DefaultPluginStore.Create(
		self.config.Backend.Plugin, self.config.Backend.PluginConfig)
	if err != nil {
		return err
	}
	var ok bool
	self.store, ok = plug.(gopnik.KVStore)
	if !ok {
		return fmt.Errorf("Invalid KV plugin")
	}

	if self.config.UseSecondLevelCache {
		self.cache2L = make(map[u8Color][]byte)
	}

	return nil
}
func (self *CouchbaseKV) Configure(cfg json.RawMessage) error {
	// Unmarshal config
	err := json.Unmarshal(cfg, &self.config)
	if err != nil {
		return err
	}

	// Defaults
	if self.config.Pool == "" {
		self.config.Pool = "default"
	}

	// Connect
	var errs []error
	for _, addr := range self.config.Addrs {
		self.bucket, err = couchbase.GetBucket(addr, self.config.Pool, self.config.Bucket)
		if err == nil {
			return nil
		} else {
			errs = append(errs, err)
		}
	}
	return fmt.Errorf("Failed to connect to couchbase: %v", errs)
}
Beispiel #11
0
func (self *FakeCachePlugin) Configure(cfg json.RawMessage) error {
	err := json.Unmarshal(cfg, &self.config)
	if err != nil {
		return err
	}
	if self.config.UseStubImage {
		self.img, err = sampledata.Asset("1_0_0.png")
		if err != nil {
			return err
		}
	}

	if self.config.GetSleep != "" {
		var err error
		self.getSleep, err = time.ParseDuration(self.config.GetSleep)
		if err != nil {
			return nil
		}
	}
	if self.config.SetSleep != "" {
		var err error
		self.setSleep, err = time.ParseDuration(self.config.SetSleep)
		if err != nil {
			return nil
		}
	}

	if self.config.SetError != "" {
		self.setError = errors.New(self.config.SetError)
	}
	if self.config.GetError != "" {
		self.getError = errors.New(self.config.GetError)
	}

	return nil
}
Beispiel #12
0
func (s *PlanSuite) SetUpSuite(c *C) {
	err := json.Unmarshal([]byte(planJson), &s.bboxes)
	if err != nil {
		panic(err)
	}
}
Beispiel #13
0
	json "github.com/orofarne/strict-json"
)

type logConfig struct {
	Backend string
	Level   string
	Format  string
	Options json.RawMessage
}

var logBackendMap = map[string]func(*logConfig) error{
	"Console": func(cfg *logConfig) error {
		var pcfg struct {
			Color bool
		}
		err := json.Unmarshal(cfg.Options, &pcfg)
		if err != nil {
			return err
		}

		logBackend := logging.NewLogBackend(os.Stderr, "", stdlog.LstdFlags|stdlog.Lshortfile)
		if pcfg.Color {
			logBackend.Color = true
		}

		logging.SetBackend(logBackend)

		return nil
	},
	"Syslog": func(cfg *logConfig) error {
		var pcfg struct {
Beispiel #14
0
func (self *FileCachePlugin) Configure(cfg json.RawMessage) error {
	self.cfg.Root = "/tmp/tiles"
	self.cfg.UseHash = true
	return json.Unmarshal(cfg, &self.cfg)
}