func main() { c := 0 webl := func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "Hello Avatar") log.Printf("Page Visited\n") } countr := func(w http.ResponseWriter, req *http.Request) { c++ fmt.Fprintf(w, "Hi there<br/>You're visiter #%v", c) log.Printf("Countr visited %v times\n", c) } sfile := func(w http.ResponseWriter, req *http.Request) { http.ServeFile(w, req, "test2") log.Printf("Served File\n") } echoUrlInfo := func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "Hi there<br/>The URL you're visiting is made up of these component parts!<br/>Gocode!:<br/>%T<br/>%#v", req, req) log.Printf("Hit URL Info page\n") } http.HandleFunc("/hello", webl) http.HandleFunc("/counter", countr) http.HandleFunc("/fileTest", sfile) http.HandleFunc("/urlInfo", echoUrlInfo) err := http.ListenAndServe(":12345", nil) if err != nil { log.Fatalf("ListenAndServe: ", err.String()) } }
func Start(ch *chan int, st *State.State) { world = *ch state = st go http.ListenAndServe(":25560", http.HandlerFunc(httpServe)) go http.ListenAndServe(":25561", websocket.Handler(wssServe)) // os.ForkExec("http://localhost:25560/index.oc", []string{}, []string{}, "", []*os.File{}) }
func main() { var err os.Error // Pull in command line options or defaults if none given flag.Parse() f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666) if err == nil { defer f.Close() log.SetOutput(f) } skylib.Setup(sName) homeTmpl = template.MustParse(homeTemplate, nil) respTmpl = template.MustParse(responseTemplate, nil) http.HandleFunc("/", homeHandler) http.HandleFunc("/new", submitHandler) rpc.HandleHTTP() portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port) err = http.ListenAndServe(portString, nil) if err != nil { log.Fatal("ListenAndServe: ", err.String()) } }
func main() { cards = make(map[string]Card) sio := socketio.NewSocketIO(nil) sio.OnConnect(func(c *socketio.Conn) { sio.Broadcast(struct{ announcement string }{"connected: " + c.String()}) }) sio.OnDisconnect(func(c *socketio.Conn) { sio.BroadcastExcept(c, struct{ announcement string }{"disconnected: " + c.String()}) }) sio.OnMessage(func(c *socketio.Conn, msg socketio.Message) { sio.BroadcastExcept(c, struct{ message []string }{[]string{c.String(), msg.Data()}}) }) mux := sio.ServeMux() mux.HandleFunc("/", resourceHandler) mux.HandleFunc("/CardService/create", createCardHandler) mux.HandleFunc("/CardService/remove", removeCardHandler) mux.HandleFunc("/CardService/move", moveCardHandler) mux.HandleFunc("/CardService/list", listCardHandler) log.Printf("About to listen on 10443. Go to https://127.0.0.1:10443/") if err := http.ListenAndServe(":10443", mux); err != nil { log.Fatal(err) } }
func main() { sio := socketio.NewSocketIO(nil) sio.OnConnect(func(c *socketio.Conn) { sio.Broadcast("connected: socket.io/" + c.String()) }) sio.OnDisconnect(func(c *socketio.Conn) { sio.BroadcastExcept(c, "disconnected: socket.io/"+c.String()) }) sio.OnMessage(func(c *socketio.Conn, msg socketio.Message) { sio.BroadcastExcept(c, msg.Data()) }) go func() { count := 0 for { sio.Broadcast(fmt.Sprintf("ping%d", count)) count++ syscall.Sleep(1e9) } }() mux := sio.ServeMux() mux.Handle("/", http.FileServer("www/", "/")) if err := http.ListenAndServe(":8080", mux); err != nil { fmt.Println("ListenAndServe:", err) } }
func echoServer(addr string, config *Config) <-chan *event { events := make(chan *event) server = NewSocketIO(config) server.OnConnect(func(c *Conn) { events <- &event{c, eventConnect, nil} }) server.OnDisconnect(func(c *Conn) { events <- &event{c, eventDisconnect, nil} }) server.OnMessage(func(c *Conn, msg Message) { if err := c.Send(msg.Data()); err != nil { fmt.Println("server echo send error: ", err) } events <- &event{c, eventMessage, msg} }) server.Mux("/socket.io/", nil) go func() { http.ListenAndServe(addr, nil) events <- &event{nil, eventCrash, nil} }() return events }
func main() { http.HandleFunc("/", handler) err := http.ListenAndServe(":8080", nil) if err != nil { log.Fatal(err) } }
func main() { var benchmark = flag.Bool("benchmark", false, "benchmark an already running server") flag.Parse() if *benchmark { done := make(chan int) go slam("foo", 10000, done) go slam("bar", 10000, done) go slam("foo", 10000, done) go slam("bar", 10000, done) <-done <-done <-done <-done } else { mqueue = NewMemoQueue() http.HandleFunc("/put", PutHandler) http.HandleFunc("/get", GetHandler) http.HandleFunc("/stats", StatsHandler) http.ListenAndServe(":8080", nil) } }
func main() { http.Handle("/", http.HandlerFunc(PushServer)) err := http.ListenAndServe(":12345", nil) if err != nil { panic("ListenAndServe: ", err.String()) } }
func main() { http.HandleFunc("/", redirHandler) http.HandleFunc("/view/", makeHandler(viewHandler)) http.HandleFunc("/edit/", makeHandler(editHandler)) http.HandleFunc("/save/", makeHandler(saveHandler)) http.ListenAndServe(":8080", nil) }
func main() { http.HandleFunc("/view/", viewHandler) http.HandleFunc("/edit/", editHandler) http.HandleFunc("/save/", saveHandler) http.ListenAndServe(":8080", nil) }
func main() { flag.Parse() http.HandleFunc("/", Root) http.HandleFunc("/static/", Static) go http.ListenAndServe(*listenAddr, nil) // The minecraft server actually writes to stderr, but reading from // stdin makes things easier since I can use bash and a pipe. stdin := bufio.NewReader(os.Stdin) for { line, err := stdin.ReadString('\n') if err != nil && err.String() == "EOF" { break } if err != nil || len(line) <= 1 { continue } ev, err := parseLine(line) if err != nil { fmt.Println("parseLine error:", err) continue } ev.Resolve() } os.Exit(0) }
func main() { log.SetFlags(0) flag.Parse() cgiHandler := &cgi.Handler{ Path: *cgitPath, Env: []string{}, InheritEnv: []string{ "CGIT_CONFIG", }, } if *config != "" { cgiHandler.Env = append(cgiHandler.Env, "CGIT_CONFIG="+*config) } fs := http.FileServer(http.Dir(*cgitRes)) http.Handle("/cgit.css", fs) http.Handle("/cgit.png", fs) http.Handle("/", cgiHandler) err := http.ListenAndServe(*addr+":"+strconv.Itoa(*port), nil) if err != nil { log.Fatal(err) } // Everything seems to work: daemonize (close file handles) os.Stdin.Close() os.Stdout.Close() os.Stderr.Close() }
// starts HTTP server based on hostname in configuration file func ListenAndServe() { hostname := GetRequiredString(configFile, "default", "hostname") logger.Debug("ListenAndServe():%v", hostname) if err := http.ListenAndServe(hostname, nil); err != nil { logger.Fatal(err.String()) } }
// HTTP listner func httpRunner() { http.HandleFunc("/", PushServer) err := http.ListenAndServe(":12345", nil) if err != nil { log.Fatal("ListenAndServe: ", err.String()) } }
func main() { err := loadTemplates() if err != nil { fmt.Println(err) return } homepage = "<a href=\"/sim/10/1/1\">Basic Simulation</a><br /><table><tr><td>SpawnTime</td><td>10 mins</tr><tr><td># Nurses</td><td>1</td></tr><tr><td># Doctors</td><td>1</td></tr></table>" // Simulation wd, err := os.Getwd() if err != nil { log.Println("ERROR: Failed to get Working Directory", err) return } //indexHtml, err := ioutil.ReadFile(wd + "/assets/index.html") //if err != nil { fmt.Println("ERROR:", err); return; } http.Handle("/assets/", http.FileServer(wd, "")) http.HandleFunc("/sim/", http.HandlerFunc(SimulationHandler)) http.HandleFunc("/", http.HandlerFunc(HomeHandler)) err = http.ListenAndServe(":6060", nil) log.Println("LOG: Server Shutting Down") if err != nil { log.Println("ERROR:", err) } }
func main() { http.HandleFunc("/", ProxyServer) err := http.ListenAndServe(":8123", nil) if err != nil { log.Exit("ListenAndServe: ", err.String()) } }
func main() { flag.Int64Var(&delay, "delay", 0, "Delay per tweet in ns.") port := flag.Int("port", 3000, "The port to bind to.") flag.Usage = usage flag.Parse() if flag.NArg() == 0 { flag.Usage() os.Exit(2) } var err os.Error fileHandle, err = os.Open(flag.Arg(0)) if err != nil { fmt.Printf("Could not open file: %s\n", flag.Arg(0)) os.Exit(2) } defer fileHandle.Close() fmt.Printf("Starting up server on port %d.\n", *port) if delay > 0 { fmt.Printf("Delaying tweets by %d ns.\n", delay) } http.HandleFunc("/", sample) http.ListenAndServe(":"+strconv.Itoa(*port), nil) }
func main() { http.Handle("/", createServer()) err := http.ListenAndServe(":12345", nil) if err != nil { log.Fatal("ListenAndServe: ", err.String()) } }
func main() { http.HandleFunc("/", starrpg.Handler) log.Print("Start!") if err := http.ListenAndServe(":3030", nil); err != nil { log.Fatal("http.ListenAndServe:", err) } }
func main() { runtime.GOMAXPROCS(8) if len(os.Args) != 3 { fmt.Fprintf(os.Stderr, "Usage: %s redirect_map pool_size\n", os.Args[0]) return } poolSize, err := strconv.Atoi(os.Args[2]) if err != nil { fmt.Fprintf(os.Stderr, "pool size must numeric\n") return } fmt.Printf("Loading redirects map...\n") redirects := loadRedirects(os.Args[1]) fmt.Printf("Connecting to databases...\n") context := Setup("127.0.0.1", "logs", "127.0.0.1:6379", 0, poolSize) fmt.Printf("Starting web server...\n") http.HandleFunc("/", makeRedirectServer(redirects, context)) err = http.ListenAndServe(":12345", nil) if err != nil { fmt.Fprintf(os.Stderr, "Can't start: %s\n", err.String()) return } }
func main() { mode := flag.Int("mode", 0, "0: Broadcast, 1: LIFO, 2: FILO") flag.Parse() config := pusher.DefaultConfiguration config.GCInterval = 0 // disable garbage collecting config.ConcurrencyMode = *mode // Create a new pusher context, where all publisher and subscriber // locations are statically mapped to "static"-channel. push := pusher.New(pusher.StaticAcceptor("static"), config) http.Handle("/pub", push.PublisherHandler) http.Handle("/sub", push.SubscriberHandler) http.Handle("/", http.FileServer("www/", "/")) // Create the "static"-channel explictly, since AllowChannelCreation is false // in the DefaultConfiguration. channel, _ := push.Channel("static") go func() { i := 0 for { channel.PublishString(fmt.Sprintf("--- Greetings from the server #%d ---", i), false) time.Sleep(10e9) i++ } }() log.Print("Tune your browser tab(s) to http://localhost:8080/") if err := http.ListenAndServe(":8080", nil); err != nil { log.Fatal(err) } }
// TODO(rh): tame copy/paste code from cammount func main() { flag.Parse() cacheDir, err := ioutil.TempDir("", "camlicache") if err != nil { log.Fatalf("Error creating temp cache directory: %v", err) } defer os.RemoveAll(cacheDir) diskcache, err := localdisk.New(cacheDir) if err != nil { log.Fatalf("Error setting up local disk cache: %v", err) } if flag.NArg() != 1 { log.Fatal("usage: camwebdav <blobref>") } br := blobref.Parse(flag.Arg(0)) if br == nil { log.Fatalf("%s was not a valid blobref.", flag.Arg(0)) } client := client.NewOrFail() fetcher := cacher.NewCachingFetcher(diskcache, client) f = fs.NewCamliFileSystem(fetcher, br) http.HandleFunc("/", webdav) err = http.ListenAndServe(*davaddr, nil) if err != nil { log.Fatalf("Error starting WebDAV server: %v", err) } }
func main() { http.HandleFunc("/", HelloServer) err := http.ListenAndServe(":"+port(), nil) if err != nil { log.Fatal("ListenAndServe: ", err.String()) } }
func DummyServer(address string, ch chan<- string) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "ocpdummy %s", r.URL.Path) ch <- r.URL.Path }) http.ListenAndServe(address, nil) }
func main() { //defer handleErrors("main",true) // der Port auf dem unser Server laufen soll port := "8080" // das Basisverzeichnis (rootdir) unseres Servers dir := "." // Kommandozeile pruefen und Werte übernehmen if len(os.Args) > 1 { port = os.Args[1] } if len(os.Args) > 2 { dir = os.Args[2] } // logkanal gepuffert eröffnen logchannel = make(chan string, 2000) // logging nebenläufig starten go loggerThread(logchannel) // und los gehts log("Der Go Chartserver startet auf Port " + port + " im Verzeichnis " + dir) // Server initialisieren os.Chdir(dir) http.HandleFunc("/pngchart", handlePngChart) http.HandleFunc("/svgchart", handleSvgChart) http.HandleFunc("/", handleFileRequest) http.ListenAndServe(fmt.Sprintf(":%s", port), nil) }
func (s *TestHTTPServer) Start() { if s.started { return } s.started = true s.request = make(chan *http.Request, 64) s.response = make(chan *testResponse, 64) s.pending = make(chan bool, 64) url, _ := url.Parse(s.URL) go http.ListenAndServe(url.Host, s) s.PrepareResponse(202, nil, "Nothing.") fmt.Fprintf(os.Stderr, "\nWaiting for the fake server to be up...") for { resp, err := http.Get(s.URL) if err == nil && resp.StatusCode == 202 { break } time.Sleep(1e8) } fmt.Fprintf(os.Stderr, "Done\n") s.WaitRequest() }
func main() { flag.Parse() // set archChar switch runtime.GOARCH { case "arm": archChar = "5" case "amd64": archChar = "6" case "386": archChar = "8" default: log.Fatalln("unrecognized GOARCH:", runtime.GOARCH) } // source of unique numbers go func() { for i := 0; ; i++ { uniq <- i } }() http.HandleFunc("/", FrontPage) http.HandleFunc("/compile", Compile) log.Fatal(http.ListenAndServe(*httpListen, nil)) }
func main() { http.Handle("/echo", websocket.Handler(EchoServer)) err := http.ListenAndServe(":12345", nil) if err != nil { panic("ListenAndServe: " + err.String()) } }
func main() { flag.Parse() runtime.GOMAXPROCS(*threads) http.Handle("/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) http.Handle("/pprof/heap", http.HandlerFunc(pprof.Heap)) http.Handle("/pprof/symbol", http.HandlerFunc(pprof.Symbol)) go func() { http.ListenAndServe("0.0.0.0:6060", nil) }() if *accesslog != "" { logf, err := os.OpenFile(*accesslog, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0644) if err != nil { log.Print("open " + *accesslog + " failed") return } memcache.AccessLog = log.New(logf, "", log.Ldate|log.Ltime) } else if *debug { memcache.AccessLog = log.New(os.Stdout, "", log.Ldate|log.Ltime) } tbefore := int64(0) if *before != "" { t, err := time.Parse(time.RFC3339[:len(*before)], *before) if err != nil { log.Print("parse time error", err.String()) return } t.ZoneOffset = 8 * 60 * 60 tbefore = t.Seconds() log.Print("load data before", t.Format(time.RFC3339)) } log.Print("start to open db ", *dbpath) store := NewStore(*dbpath, *dbdepth, tbefore) defer store.Close() addr := fmt.Sprintf("%s:%d", *listen, *port) s := memcache.NewServer(store) e := s.Listen(addr) if e != nil { log.Print("Listen at ", *listen, "failed") return } // monitor mem usage go func() { ul := uint64(*memlimit) * 1024 * 1024 for runtime.MemStats.HeapSys < ul { time.Sleep(1e9) } log.Print("Mem used by Go is over limitation ", runtime.MemStats.HeapSys/1024/1024, *memlimit) s.Shutdown() }() s.Serve() log.Print("shut down gracefully.") }