示例#1
0
文件: util.go 项目: haiheipijuan/kasi
func parseSourceList(itemConfig *config.Config) ([]string, error) {
	rawSources, err := itemConfig.List("source")
	if err != nil {
		return nil, err
	}

	var sources []string
	for i := 0; i < len(rawSources); i++ {
		source, err := itemConfig.String(fmt.Sprintf("source.%d", i))
		if err != nil {
			return nil, err
		}

		if len(kasi_util.Trim(source)) < 1 {
			continue
		}
		sourceUrl, err := parseOneSource(source)
		if err != nil {
			return nil, err
		}
		sources = append(sources, sourceUrl)
	}

	return sources, nil
}
示例#2
0
文件: util.go 项目: haiheipijuan/kasi
func parseSource(itemConfig *config.Config) ([]string, error) {
	var err error

	_, err = itemConfig.String("source")
	if err == nil {
		return parseSourceString(itemConfig)
	}

	_, err = itemConfig.List("source")
	return parseSourceList(itemConfig)
}
示例#3
0
func parseMiddlewares(itemConfig *config.Config) (MiddlewaresSetting, error) {
	items, err := itemConfig.List("")
	if err != nil {
		return nil, err
	}

	middlewares := MiddlewaresSetting{}

	for i := 0; i < len(items); i++ {
		var name string
		{
			item, err := itemConfig.Map(fmt.Sprintf("%d", i))
			if err != nil {
				continue
			}
			// get name
			for k, _ := range item {
				name = k
			}
		}

		ms, err := itemConfig.List(fmt.Sprintf("%d.%s", i, name))
		if err != nil {
			return nil, err
		}

		middlewares[name] = MiddlewareSetting{}
		for j := 0; j < len(ms); j++ {
			m, err := itemConfig.String(fmt.Sprintf("%d.%s.%d", i, name, j))
			if err != nil {
				return nil, err
			}
			middlewares[name] = append(middlewares[name], m)
		}
	}

	return middlewares, nil
}
示例#4
0
func (mgr *pluginManager) Start(options *config.Config) error {

	plugins, err := options.List("plugins")
	if err != nil {
		logrus.Warnf("Plugins: No configuration section found")
		return err
	}

	for _, plug := range plugins {
		plugin_conf := plug.(map[string]interface{})

		pluginType, ok := utils.GetString("type", plugin_conf, "")
		if !ok {
			logrus.Warnf("Plugins: failed to get type for '%s'", plugin_conf)
			continue
		}

		plugin := mgr.known_plugins[pluginType]

		if plugin != nil {
			err = plugin.Start(plugin_conf)
			if err != nil {
				logrus.Warnf("Plugins: failed to start plugin: '%s' error: '%s'", plugin.Name(), err)
				continue
			}

			mgr.plugins[plugin.Name()] = plugin
			logrus.Infof("Plugins: plugin started successfully: '%s'", plugin.Name())
		} else {
			logrus.Warnf("Plugins: plugin does not exists: '%s'", pluginType)
		}
	}

	eventbus.EventBus.Subscribe(eventbus.HOME_SHUTDOWN, mgr.Stop)

	return nil
}