Ejemplo n.º 1
0
func getPathFromParameterAndLoadConfigFile() {
	path := ""
	if len(os.Args) > 1 {
		path = os.Args[0]
	}
	config.LoadConfig(path)
}
Ejemplo n.º 2
0
func TestConfig(t *testing.T) {

	conf, err := config.LoadConfig("config.json")
	if err != nil {
		log.Fatal("load err", err)
	}

	fmt.Println(conf)

}
Ejemplo n.º 3
0
func main() {
	conf, err := config.LoadConfig("config/config.json")
	if err != nil {
		log.Fatal("load err", err)
	}

	fmt.Println(conf)
	var p = conf["Phone"]
	fmt.Printf("%v,%T\n", p, p)
	fmt.Println(conf["Phone"])

	k := []byte("efwfw")
	c, err := aes.NewCipher(k)
	if err == nil {
		log.Print("Hello")
		log.Print(err)
	}
	log.Print(c)
	//	var dst []byte = make([]byte,50)
	//	var src string = "ok";
	//	src.getBytes()
	//	c.Encrypt(dst,[]byte("ok") )
	//	log.Print(dst)
}
Ejemplo n.º 4
0
func main() {
	config.LoadConfig()
	fmt.Println("Hello, go!")
}
Ejemplo n.º 5
0
// Start the valkyrie web-server.
func main() {

	// Bind address
	bindAddress := flag.String("bind", ":443", "The address and port to bind to")

	// TLS
	useTLS := flag.Bool("tls", true, "Listen / Serve using TLS")
	tlsCert := flag.String("cert", "cert.pem", "The TLS certificate file")
	tlsKey := flag.String("key", "key.pem", "The TLS key file")

	// Rate limit
	doThrottle := flag.Bool("throttle", true, "Rate limit the server")
	reqPerSec := flag.Float64("rate", 1100.0, "Rate limit req/sec")

	// Network
	timeout := flag.Int("timeout", 30, "Back-end service timeout in seconds")
	keepAlive := flag.Bool("keepalive", true, "Whether to re-use TCP connections between requests")
	compression := flag.Bool("compress", false, "Whether a compression header can be added to requests")
	maxIdle := flag.Int("maxidle", 10, "The maximum idle connections (keep-alive) to keep per-host")

	// Cassandra config
	keyspace := flag.String("keyspace", "valkyrie", "The cassandra configuration keyspace")
	user := flag.String("user", "valkyrie", "The cassandra user")
	pass := flag.String("pass", "valkyrie", "The cassandra password")
	cp := flag.String("cp", "localhost", "The comma-separated list of cassandra contact points")

	// service discovery config
	discoType := flag.String("disco", "consul", "service discover type")
	discoAddress := flag.String("discoAddress", "localhost:8500", "address for the service discovery endpoint")

	// Stats reporter
	reportTo := flag.String("report", "console", "The stats reporter to use")

	// Parse the command line flags listed above
	flag.Parse()

	// Init cassandra credentials
	cassandraArgs := append([]string{*keyspace, *user, *pass}, strings.Split(*cp, ",")...)

	// Load config
	cfg, err := config.LoadConfig("cassandra", cassandraArgs...)
	if err != nil {
		log.Fatal(err)
	}
	defer cfg.Close()

	// Init transport and dispatcher
	timeoutDuration := time.Duration(*timeout) * time.Second
	txp := transport.NewDialTimeoutTransport(timeoutDuration, !*keepAlive, !*compression, *maxIdle)
	dispatcher := core.NewDispatcher(txp, cfg)

	// Load stats reporter
	var reporter stats.ValkyrieStats
	if *reportTo == "cassandra" {
		reporter, err = stats.LoadStatsReporter(*reportTo, cassandraArgs...)
	} else {
		reporter, err = stats.LoadStatsReporter(*reportTo)
	}
	if err != nil {
		log.Fatal(err)
	}
	defer reporter.Close()
	dispatcher.ReportTo(reporter)

	var discovery disco.ValkyrieDisco
	if *discoType == "consul" {
		discovery, err = disco.LoadServiceDiscovery(*discoType, *discoAddress)
	} else {
		discovery, err = disco.LoadServiceDiscovery(*discoType)
	}
	if err != nil {
		log.Fatal(err)
	}
	dispatcher.DiscoverFrom(discovery)

	// Init http multiplexer
	mux := http.NewServeMux()
	if *doThrottle {
		throttle := time.Tick(time.Second / time.Duration(*reqPerSec))
		mux.Handle("/", dispatcher.DispatchHandler(throttle))
	} else {
		log.Println("Warning: rate limit disabled")
		mux.Handle("/", dispatcher.DispatchHandler(nil))
	}

	// Start server
	log.Println("Starting the valkyrie web-server on", *bindAddress)
	srv := &http.Server{Handler: mux, Addr: *bindAddress}
	if *useTLS {
		err = srv.ListenAndServeTLS(*tlsCert, *tlsKey)
	} else {
		log.Println("Warning: TLS disabled")
		err = srv.ListenAndServe()
	}
	if err != nil {
		log.Fatal("Unable to start web server: ", err)
	}
}