当前位置: 首页>>代码示例>>Golang>>正文


Golang http.HandleFunc函数代码示例

本文整理汇总了Golang中http.HandleFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang HandleFunc函数的具体用法?Golang HandleFunc怎么用?Golang HandleFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了HandleFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

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)
	}

}
开发者ID:ghthor,项目名称:hospitSim.go,代码行数:31,代码来源:main.go

示例2: main

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)
}
开发者ID:SnertSnert,项目名称:turbulentflyer,代码行数:31,代码来源:Chartserver.go

示例3: main

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)
}
开发者ID:nictuku,项目名称:gomine,代码行数:25,代码来源:main.go

示例4: init

func init() {
	http.HandleFunc("/", SearchHandler)
	http.HandleFunc("/upload", UploadHandler)
	http.HandleFunc("/process/gedcom", GedcomHandler)
	searchTemplate = create_template("canvas.html")
	uploadTemplate = create_template("upload.html")
}
开发者ID:phython,项目名称:boyd-search,代码行数:7,代码来源:search.go

示例5: main

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)
	}
}
开发者ID:thatmattbone,项目名称:lab,代码行数:29,代码来源:memoserver.go

示例6: main

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())
	}
}
开发者ID:repos-go,项目名称:skynet,代码行数:30,代码来源:web.go

示例7: main

func main() {
	http.HandleFunc("/", redirHandler)
	http.HandleFunc("/view/", makeHandler(viewHandler))
	http.HandleFunc("/edit/", makeHandler(editHandler))
	http.HandleFunc("/save/", makeHandler(saveHandler))
	http.ListenAndServe(":8080", nil)
}
开发者ID:rassware,项目名称:GoWiki,代码行数:7,代码来源:wiki.go

示例8: init

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()
}
开发者ID:nicneo925,项目名称:appscale,代码行数:29,代码来源:mandelbrot.go

示例9: main

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)
	}
}
开发者ID:raumzeitlabor,项目名称:hausbus2-go,代码行数:27,代码来源:example.go

示例10: init

func init() {
	http.HandleFunc("/", root)
	http.HandleFunc("/get", get)
	http.HandleFunc("/put", put)
	http.HandleFunc("/query", query)
	http.HandleFunc("/delete", delete)
}
开发者ID:shatterednirvana,项目名称:Active-Cloud-DB---Go-Edition,代码行数:7,代码来源:acdb.go

示例11: main

func main() {
	http.HandleFunc("/view/", viewHandler)
	http.HandleFunc("/edit/", editHandler)
	http.HandleFunc("/save/", saveHandler)

	http.ListenAndServe(":8080", nil)
}
开发者ID:ash,项目名称:go-tests,代码行数:7,代码来源:wiki.go

示例12: main

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))
}
开发者ID:ssrl,项目名称:go,代码行数:26,代码来源:goplay.go

示例13: main

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())
	}
}
开发者ID:Fumon,项目名称:fugoServer,代码行数:28,代码来源:simpleserv.go

示例14: main

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())
	}
}
开发者ID:jmptrader,项目名称:goqueue,代码行数:8,代码来源:main.go

示例15: main

func main() {
	flag.Parse()
	rpc.Register(server)
	rpc.HandleHTTP()
	http.HandleFunc("/", Static)
	http.HandleFunc("/get", Get)
	http.ListenAndServe(*listenAddr, nil)
}
开发者ID:andradeandrey,项目名称:stat,代码行数:8,代码来源:stats.go


注:本文中的http.HandleFunc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。