Beispiel #1
0
func main() {
	flagSet := flag.CommandLine
	flags := parseFlags(flagSet)
	log.Printf("Flags: %+v", flags)

	oinker := &Oinker{}

	if *flags.cassandraAddr != "" {
		oinker.CQLHosts = []string{*flags.cassandraAddr}
	} else if *flags.cassandraSRV != "" && *flags.cassandraDNS == "" || *flags.cassandraSRV == "" && *flags.cassandraDNS != "" {
		log.Fatalf("Invalid input: cassandra-srv and cassandra-dns must both be specified to enable cassandra usage")
	} else if *flags.cassandraSRV != "" && *flags.cassandraDNS != "" {
		hosts, err := lookupCassandraHosts(*flags.cassandraSRV, *flags.cassandraDNS)
		if err != nil {
			log.Fatalf("Error looking up Cassandra SRV records: %s", err)
		}
		oinker.CQLHosts = hosts
	}

	graph := oinker.NewGraph()

	var oinkRepo model.OinkRepo
	inject.ExtractAssignable(graph, &oinkRepo)
	err := oinkRepo.Init()
	if err != nil {
		log.Fatalf("Error Initializing Repo: %s", err)
	}

	var mux controller.MuxServer
	inject.ExtractAssignable(graph, &mux)

	var controllers []controller.Controller
	inject.FindAssignable(graph, &controllers)
	for _, c := range controllers {
		log.Println("Registering controller:", c.Name())
		c.RegisterHandlers(mux)
	}

	// serve and listen for shutdown signals
	gracehttp.Serve(
		&http.Server{Addr: *flags.address, Handler: mux},
	)
}
Beispiel #2
0
func main() {
	flagSet := flag.CommandLine
	flags := parseFlags(flagSet)
	log.Infof("Flags: %+v", flags)

	oinker := &Oinker{}

	if *flags.cassandraAddr != "" {
		oinker.CQLHosts = []string{*flags.cassandraAddr}
		oinker.CQLReplicationFactor = *flags.cassandraRepl
	}

	graph := oinker.NewGraph()
	defer graph.Finalize()

	// initialize cassandra (connection, keyspace, tables)
	var oinkRepo service.OinkRepo
	inject.ExtractAssignable(graph, &oinkRepo)
	svc, ok := oinkRepo.(inject.Initializable)
	if ok {
		svc.Initialize()
	}

	var mux controller.MuxServer
	inject.ExtractAssignable(graph, &mux)

	var controllers []controller.Controller
	inject.FindAssignable(graph, &controllers)
	for _, c := range controllers {
		log.Infof("Registering controller:", c.Name())
		c.RegisterHandlers(mux)
	}

	// serve and listen for shutdown signals
	gracehttp.Serve(
		&http.Server{Addr: *flags.address, Handler: mux},
	)
}