Ejemplo n.º 1
1
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())
	}
}
Ejemplo n.º 2
0
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)
}
Ejemplo n.º 3
0
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)
	}

}
Ejemplo n.º 4
0
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)
}
Ejemplo n.º 5
0
Archivo: wiki.go Proyecto: ash/go-tests
func main() {
	http.HandleFunc("/view/", viewHandler)
	http.HandleFunc("/edit/", editHandler)
	http.HandleFunc("/save/", saveHandler)

	http.ListenAndServe(":8080", nil)
}
func init() {
	http.HandleFunc("/", root)
	http.HandleFunc("/get", get)
	http.HandleFunc("/put", put)
	http.HandleFunc("/query", query)
	http.HandleFunc("/delete", delete)
}
Ejemplo n.º 7
0
func main() {
	flag.Parse()

	fmt.Println("ohai")

	http.HandleFunc("/lock_door", handleLock)
	http.HandleFunc("/unlock_door", handleUnlock)
	rzlbus.Init()
	rzlbus.SetState("pinpad.door", "locked")
	rzlbus.SetWritableState("pinpad.msg", "",
		func(key string, oldValue interface{}, newValue interface{}) {
			fmt.Println("I should change the LCD message to:")
			switch vv := newValue.(type) {
			case string:
				fmt.Println(vv)
			default:
				fmt.Println("ERROR: The message is not of type string.")
			}
		})

	for {
		rzlbus.SetState("pinpad.door", "locked")
		time.Sleep(1 * 1000 * 1000)
		rzlbus.SetState("pinpad.door", "open")
		time.Sleep(1 * 1000 * 1000)
	}
}
Ejemplo n.º 8
0
func init() {
	http.HandleFunc("/", SearchHandler)
	http.HandleFunc("/upload", UploadHandler)
	http.HandleFunc("/process/gedcom", GedcomHandler)
	searchTemplate = create_template("canvas.html")
	uploadTemplate = create_template("upload.html")
}
Ejemplo n.º 9
0
func main() {
	http.HandleFunc("/", redirHandler)
	http.HandleFunc("/view/", makeHandler(viewHandler))
	http.HandleFunc("/edit/", makeHandler(editHandler))
	http.HandleFunc("/save/", makeHandler(saveHandler))
	http.ListenAndServe(":8080", nil)
}
Ejemplo n.º 10
0
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())
	}
}
Ejemplo n.º 11
0
Archivo: goplay.go Proyecto: ssrl/go
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))
}
Ejemplo n.º 12
0
func init() {
	http.HandleFunc("/", frontPageHandler)
	http.HandleFunc("/tiles", tileHandler)

	for i := range color {
		// Use a broader range of color for low intensities.
		if i < 255/10 {
			color[i] = image.RGBAColor{uint8(i * 10), 0, 0, 0xFF}
		} else {
			color[i] = image.RGBAColor{0xFF, 0, uint8(i - 255/10), 0xFF}
		}
	}

	tmpl := template.New(nil)
	tmpl.SetDelims("{{", "}}")
	if err := tmpl.ParseFile("map.html"); err != nil {
		frontPage = []byte("tmpl.ParseFile failed: " + err.String())
		return
	}
	b := new(bytes.Buffer)
	data := map[string]interface{}{
		"InProd": !appengine.IsDevAppServer(),
	}
	if err := tmpl.Execute(b, data); err != nil {
		frontPage = []byte("tmpl.Execute failed: " + err.String())
		return
	}
	frontPage = b.Bytes()
}
Ejemplo n.º 13
0
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)
	}
}
Ejemplo n.º 14
0
func main() {
	flag.Parse()
	rpc.Register(server)
	rpc.HandleHTTP()
	http.HandleFunc("/", Static)
	http.HandleFunc("/get", Get)
	http.ListenAndServe(*listenAddr, nil)
}
Ejemplo n.º 15
0
Archivo: main.go Proyecto: kenu/You.RL
func main() {
	flag.Parse()
	store = new(URLStore)

	http.HandleFunc("/", Redirect)
	http.HandleFunc("/shorten", Shorten)
	http.ListenAndServe(":"+*listenAddr, nil)
}
Ejemplo n.º 16
0
func main() {
	http.HandleFunc("/subscribe", subscribe) // Subsribers must declare themselves using this URI
	http.HandleFunc("/publish", publish)     // producers can publish messages using this URI
	err := http.ListenAndServe(":12345", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err.String())
	}
}
Ejemplo n.º 17
0
func Serve(listener net.Listener) {
	http.HandleFunc("/", viewHtml)
	http.HandleFunc("/$stats.html", statsHtml)
	http.Handle("/$main.js", stringHandler{"application/javascript", main_js})
	http.Handle("/$main.css", stringHandler{"text/css", main_css})
	http.HandleFunc("/$events/", evServer)

	http.Serve(listener, nil)
}
Ejemplo n.º 18
0
func main() {
	http.HandleFunc("/process", Server)
	http.HandleFunc("/file", ProcessServer)
	http.HandleFunc("/", FileServer)
	err := http.ListenAndServe(":1234", nil)
	if err != nil {
		println("Fatal error occured, program needs to close")
	}
}
Ejemplo n.º 19
0
func main() {
  http.HandleFunc("/", handleRoot)
  http.HandleFunc("/shorten", handleShorten)
  http.HandleFunc("/lengthen", handleLengthen)
  
  http.ListenAndServe("localhost:8080", nil)
  
  
}
Ejemplo n.º 20
0
func main() {
	flag.Parse()
	go hub()
	http.HandleFunc("/", homeHandler)
	http.HandleFunc("/ws", webSocketProtocolSwitch)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
Ejemplo n.º 21
0
func main() {
	flag.Parse()

	go proxyMuxer()

	http.HandleFunc("/", handler)
	http.HandleFunc("/create", createHandler)
	http.ListenAndServe(*httpAddr, nil)
}
Ejemplo n.º 22
0
func init() {
	for _, name := range []string{"500", "404", "report"} {
		tmpl := template.Must(template.New(name).ParseFile("jshint/templates/" + name + ".html"))
		templates[name] = tmpl
	}

	http.HandleFunc("/reports/save/", save)
	http.HandleFunc("/reports/", show)
	http.HandleFunc("/", notFound)
}
Ejemplo n.º 23
0
func main() {
	//	p1 := &Page{Title: "TestPage", Body: []byte("I'm a test page.")}
	//	p1.save()
	//	p2, _ := loadPage("TestPage")
	flag.Parse()
	http.HandleFunc("/view/", viewHandler)
	http.HandleFunc("/edit/", editHandler)
	http.HandleFunc("/save/", saveHandler)
	http.ListenAndServe(":"+*port, nil)
}
Ejemplo n.º 24
0
func main() {
	http.HandleFunc("/", baseHandler)
	http.HandleFunc(view, viewHandler)
	http.HandleFunc(save, saveHandler)
	http.HandleFunc(edit, editHandler)
	http.HandleFunc(tag, tagHandler)
	http.ListenAndServe(port, nil)
	//get map loaded
	Load(tagsPath + tagsFile)
}
Ejemplo n.º 25
0
func main() {
	fmt.Printf("Loading photos server...\n")
	template.SetModuleName("photos")
	http.HandleFunc("/photos/", Handler)
	http.HandleFunc("/photos/upload", UploaderHandler)
	// TODO: Move these to their own module.
	// We have to get sessions to transfer between processes correctly before we can do that, however.
	http.HandleFunc("/picasa/auth", AuthHandler)
	http.HandleFunc("/picasa/upload", UploadHandler)
	http.ListenAndServe(":8090", nil)
}
Ejemplo n.º 26
0
func main() {
	http.HandleFunc("/drafts", DraftsServer)
	http.HandleFunc("/pdf/", PDFServer)
	http.HandleFunc("/", IndexServer)

	log.Println("Starting Server")
	err := http.ListenAndServe("127.0.0.1:3000", nil)
	if err != nil {
		log.Fatal("Listen and Serve: ", err.String())
	}
}
Ejemplo n.º 27
0
func main() {
	easysocket.Handle("/", NewClient)
	http.HandleFunc("/favicon.ico", faviconServer)
	http.HandleFunc("/style.css", styleServer)
	http.HandleFunc("/style-fourcolor.css", styleServer)
	http.HandleFunc("/speech/", wavServer)
	err := http.ListenAndServe(":12345", nil)
	if err != nil {
		panic("ListenAndServe: " + err.String())
	}
}
Ejemplo n.º 28
0
func main() {
	data["barsoom"] = Book{Title: "Barsoom", Content: ReadBook("barsoom1.txt")}
	data["crusoe"] = Book{Title: "Robinson Crusoe", Content: ReadBook("crusoe.txt")}
	data["holmes"] = Book{Title: "Sherlock Holmes", Content: ReadBook("holmes1.txt")}
	dictionary = ReadDict("dictionary.txt")

	http.HandleFunc("/words/", WordsHandler)
	http.HandleFunc("/book/", BookHandler)
	http.HandleFunc("/", NoHandler)
	http.ListenAndServe(":5678", nil)
}
Ejemplo n.º 29
0
func main() {
	flag.Parse()
	http.HandleFunc("/", rootHandler)
	http.HandleFunc("/log", logHandler)
	http.HandleFunc("/eval", evalHandler)
	println("Listening on", *address)
	err := http.ListenAndServe(*address, nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.String())
	}
}
Ejemplo n.º 30
0
func serveHTTP() {
	server := ProcFSServer{}
	rpc.RegisterName("ProcFS", server)
	http.HandleFunc("/", HTMLServer)
	http.HandleFunc("/rpc", RPCServer)

	err := http.ListenAndServe(*http_port, http.DefaultServeMux)
	if err != nil {
		log.Print("ERR: ", err)
	}
}