carbon/app.go
func (app *App) configure() error {
	var err error

	cfg, err := ReadConfig(app.ConfigFilename)
	if err != nil {
		return err
	}

	// carbon-cache prefix
	if hostname, err := os.Hostname(); err == nil {
		hostname = strings.Replace(hostname, ".", "_", -1)
		cfg.Common.GraphPrefix = strings.Replace(cfg.Common.GraphPrefix, "{host}", hostname, -1)
	} else {
		cfg.Common.GraphPrefix = strings.Replace(cfg.Common.GraphPrefix, "{host}", "localhost", -1)
	}

	if cfg.Whisper.Enabled {
		cfg.Whisper.Schemas, err = persister.ReadWhisperSchemas(cfg.Whisper.SchemasFilename)
		if err != nil {
			return err
		}

		if cfg.Whisper.AggregationFilename != "" {
			cfg.Whisper.Aggregation, err = persister.ReadWhisperAggregation(cfg.Whisper.AggregationFilename)
			if err != nil {
				return err
			}
		} else {
			cfg.Whisper.Aggregation = persister.NewWhisperAggregation()
		}
	}
	if !(cfg.Cache.WriteStrategy == "max" ||
		cfg.Cache.WriteStrategy == "sorted" ||
		cfg.Cache.WriteStrategy == "noop") {
		return fmt.Errorf("go-carbon support only \"max\", \"sorted\"  or \"noop\" write-strategy")
	}

	if cfg.Common.MetricEndpoint == "" {
		cfg.Common.MetricEndpoint = MetricEndpointLocal
	}

	if cfg.Common.MetricEndpoint != MetricEndpointLocal {
		u, err := url.Parse(cfg.Common.MetricEndpoint)

		if err != nil {
			return fmt.Errorf("common.metric-endpoint parse error: %s", err.Error())
		}

		if u.Scheme != "tcp" && u.Scheme != "udp" {
			return fmt.Errorf("common.metric-endpoint supports only tcp and udp protocols. %#v is unsupported", u.Scheme)
		}
	}

	app.Config = cfg

	return nil
}
func (app *App) configure() error {
	var err error

	cfg, err := ReadConfig(app.ConfigFilename)
	if err != nil {
		return err
	}

	// carbon-cache prefix
	if hostname, err := os.Hostname(); err == nil {
		hostname = strings.Replace(hostname, ".", "_", -1)
		cfg.Common.GraphPrefix = strings.Replace(cfg.Common.GraphPrefix, "{host}", hostname, -1)
	} else {
		cfg.Common.GraphPrefix = strings.Replace(cfg.Common.GraphPrefix, "{host}", "localhost", -1)
	}

	if cfg.Whisper.Enabled {
		cfg.Whisper.Schemas, err = persister.ReadWhisperSchemas(cfg.Whisper.SchemasFilename)
		if err != nil {
			return err
		}

		if cfg.Whisper.AggregationFilename != "" {
			cfg.Whisper.Aggregation, err = persister.ReadWhisperAggregation(cfg.Whisper.AggregationFilename)
			if err != nil {
				return err
			}
		} else {
			cfg.Whisper.Aggregation = persister.NewWhisperAggregation()
		}
	}
	if !(cfg.Cache.WriteStrategy == "max" ||
		cfg.Cache.WriteStrategy == "sorted" ||
		cfg.Cache.WriteStrategy == "noop") {
		return fmt.Errorf("go-carbon support only \"max\", \"sorted\"  or \"noop\" write-strategy")
	}

	if cfg.Common.MetricEndpoint == "" {
		cfg.Common.MetricEndpoint = MetricEndpointLocal
	}

	if cfg.Common.MetricEndpoint != MetricEndpointLocal {
		u, err := url.Parse(cfg.Common.MetricEndpoint)

		if err != nil {
			return fmt.Errorf("common.metric-endpoint parse error: %s", err.Error())
		}

		if u.Scheme != "tcp" && u.Scheme != "udp" {
			return fmt.Errorf("common.metric-endpoint supports only tcp and udp protocols. %#v is unsupported", u.Scheme)
		}
	}

	app.Config = cfg

	return nil
}
func ( app * App ) configure ( ) error { var err error cfg , err := ReadConfig ( app . ConfigFilename ) if err != nil { return err } // carbon-cache prefix if hostname , err := os . Hostname ( ) ; err == nil { hostname = strings . Replace ( hostname , " " , " " , - 1 ) cfg . Common . GraphPrefix = strings . Replace ( cfg . Common . GraphPrefix , " " , hostname , - 1 ) } else { cfg . Common . GraphPrefix = strings . Replace ( cfg . Common . GraphPrefix , " " , " " , - 1 ) } if cfg . Whisper . Enabled { cfg . Whisper . Schemas , err = persister . ReadWhisperSchemas ( cfg . Whisper . SchemasFilename ) if err != nil { return err } if cfg . Whisper . AggregationFilename != " " { cfg . Whisper . Aggregation , err = persister . ReadWhisperAggregation ( cfg . Whisper . AggregationFilename ) if err != nil { return err } } else { cfg . Whisper . Aggregation = persister . NewWhisperAggregation ( ) } } if ! ( cfg . Cache . WriteStrategy == " " || cfg . Cache . WriteStrategy == " " || cfg . Cache . WriteStrategy == " " ) { return fmt . Errorf ( " \" \" \" \" \" \" " ) } if cfg . Common . MetricEndpoint == " " { cfg . Common . MetricEndpoint = MetricEndpointLocal } if cfg . Common . MetricEndpoint != MetricEndpointLocal { u , err := url . Parse ( cfg . Common . MetricEndpoint ) if err != nil { return fmt . Errorf ( " " , err . Error ( ) ) } if u . Scheme != " " && u . Scheme != " " { return fmt . Errorf ( " " , u . Scheme ) } } app . Config = cfg return nil }
// configure loads config from config file, schemas.conf, aggregation.conf
configure loads config from config file schemas . conf aggregation . conf