func (me *Coordinator) ServeHTTP(port int) { me.Mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { me.rootHandler(w, req) }) me.Mux.HandleFunc("/worker", func(w http.ResponseWriter, req *http.Request) { me.workerHandler(w, req) }) me.Mux.HandleFunc("/workerkill", func(w http.ResponseWriter, req *http.Request) { me.killHandler(w, req) }) rpcServer := rpc.NewServer() if err := rpcServer.Register(me); err != nil { log.Fatal(err) } me.Mux.HandleFunc(rpc.DefaultRPCPath, func(w http.ResponseWriter, req *http.Request) { rpcServer.ServeHTTP(w, req) }) addr := fmt.Sprintf(":%d", port) log.Println("Coordinator listening on", addr) httpServer := http.Server{ Addr: addr, Handler: me.Mux, } err := httpServer.ListenAndServe() if err != nil { log.Fatal("ListenAndServe: ", err.String()) } }
func ListenAndServe(addr string) os.Error { // TODO(kevlar): add instrumentation for examining modifications server := http.Server{ Addr: addr, Handler: DefaultServeMux, } return server.ListenAndServe() }
func main() { //Load logging configuration l4g.LoadConfiguration("logging.xml") //Load default config file var configPath string flag.StringVar(&configPath, "config", "/etc/gosolr/gosolr.cfg", "Path to the configuration file") flag.Parse() config = loadConfig(configPath) //Load solr servers/cores from mysql db solrServers = loadSolrServers(config) prettyPrint(solrServers) //Setup the http proxy stuff for apiKey := range solrServers { urlPath := "/" + apiKey http.HandleFunc(urlPath, handleRequest) } var err os.Error var srv http.Server srv.Addr = config["default"]["host"] + ":" + config["default"]["port"] srv.Handler = nil if srv.ReadTimeout, err = strconv.Atoi64(config["default"]["read_timeout"]); err != nil { l4g.Error("Configuration error. Bad read_timout value") os.Exit(1) } if srv.WriteTimeout, err = strconv.Atoi64(config["default"]["write_timeout"]); err != nil { l4g.Error("Configuration error. Bad write_timeout value") os.Exit(1) } //If this were real, this should be TLS if err := srv.ListenAndServe(); err != nil { l4g.Error("Error starting server: %s", err.String()) os.Exit(1) } }