Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
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)
}
Ejemplo n.º 3
0
func parseSourceString(itemConfig *config.Config) ([]string, error) {
	rawSource, err := itemConfig.String("source")
	if err != nil {
		return nil, err
	}

	var sources []string
	for _, i := range strings.Split(rawSource, ",") {
		if len(kasi_util.Trim(i)) < 1 {
			continue
		}
		sourceUrl, err := parseOneSource(i)
		if err != nil {
			return nil, err
		}
		sources = append(sources, sourceUrl)
	}

	return sources, nil
}
Ejemplo n.º 4
0
func (setting MiddlewaresSetting) parseMiddlewareSetting(itemConfig *config.Config, defaultName string) (MiddlewareSetting, error) {
	enabled, err := itemConfig.Bool("middleware")
	if err == nil && !enabled {
		return nil, nil
	}

	middlewareName, err := itemConfig.String("middleware")
	if err != nil {
		if len(defaultName) < 1 {
			return nil, nil
		}
		middlewareName = defaultName
	}

	if middleware, found := setting[middlewareName]; found {
		return middleware, nil
	}

	return nil, errors.New(fmt.Sprintf("invalid middleware found, `%s`", middlewareName))
}
Ejemplo n.º 5
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
}