예제 #1
0
func (r *YamlRepo) GetAddress() (RabbitAddress, error) {
	var cfg Config

	if err := config.Bind(r.Path, &cfg); err != nil {
		return RabbitAddress{}, err
	}
	return connectionConfigToAddress(r.Kr, cfg.Connection, r.Lb)
}
예제 #2
0
파일: main.go 프로젝트: macedo/weather-go
func main() {
	// Get Arguments
	var cfgPath string

	flag.StringVar(&cfgPath, "config", "./config.yaml", "Path to Config File")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s [arguments] <command> \n", os.Args[0])
		flag.PrintDefaults()
	}

	flag.Parse()

	// Load Config
	var cfg struct {
		Bind     string
		Database string
	}
	if err := config.Bind(cfgPath, &cfg); err != nil {
		log.Fatal(err)
	}

	// pull desired command/operation from args
	if flag.NArg() == 0 {
		flag.Usage()
		log.Fatal("Command argument required")
	}
	cmd := flag.Arg(0)

	// Configure Server
	s, err := location.NewLocationService(cfg.Bind, cfg.Database)
	if err != nil {
		log.Fatal(err)
	}
	// Run Main App
	switch cmd {
	case "serve":

		// Start Server
		if err := s.Run(); err != nil {
			log.Fatal(err)
		}
	case "migrate-db":

		// Start Server
		if err := s.MigrateDb(); err != nil {
			log.Fatal(err)
		}
	default:
		flag.Usage()
		log.Fatalf("Unknown Command: %s", cmd)
	}

}
예제 #3
0
func (r *YamlRepo) GetEndpoints() ([]EndpointConfig, error) {
	var cfg Config

	if err := config.Bind(r.Path, &cfg); err != nil {
		return make([]EndpointConfig, 0), err
	}

	for i, _ := range cfg.Endpoints {
		cfg.Endpoints[i].Lb = r.Lb
	}
	return cfg.Endpoints, nil
}
예제 #4
0
func TestConfig(t *testing.T) {
	// given
	cfgPath := "../test.yaml"

	// when
	cfg := &Config{}
	err := config.Bind(cfgPath, cfg)

	//then
	assert.Nil(t, err)
	assert.Equal(t, "UT", cfg.Stash.ProjKey, "project key looks wrong")
}
예제 #5
0
func (s *TestSuite) SetUpSuite(c *C) {
	var cfg struct {
		Database string
	}

	var _ = config.Bind("../test.yaml", &cfg)

	host := fmt.Sprintf("localhost:%d", rando.Port())

	db, _ := DbOpen(cfg.Database)

	s.s = &LocationService{
		Db:            db,
		Bind:          host,
		WeatherClient: &WeatherClientStub{},
	}
	go s.s.Run()

	s.host = "http://" + host
}
예제 #6
0
func Load(cfgPath string) (*Config, error) {
	cfgPath, err := normalizePath(cfgPath)
	if err != nil {
		return nil, err
	}

	cfg := &Config{}
	if err := config.Bind(cfgPath, cfg); err != nil {
		return nil, err
	}
	b, err := base64.StdEncoding.DecodeString(cfg.Stash.AuthEncoded)
	if err != nil {
		return nil, err
	}
	parts := strings.Split(string(b[:]), ":")
	if len(parts) != 2 {
		return cfg, nil
	}
	cfg.Stash.Login = parts[0]
	cfg.Stash.Password = parts[1]

	return cfg, err
}