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


Golang http.ListenAndServe函数代码示例

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


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

示例1: Start

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

示例2: 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

示例3: main

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

示例4: main

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

示例5: main

func main() {
	http.HandleFunc("/", handler)
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:surma-dump,项目名称:httpextract,代码行数:7,代码来源:httpextract.go

示例6: echoServer

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
}
开发者ID:andradeandrey,项目名称:go-socket.io,代码行数:25,代码来源:socketio_test.go

示例7: main

func main() {
	http.Handle("/", http.HandlerFunc(PushServer))
	err := http.ListenAndServe(":12345", nil)
	if err != nil {
		panic("ListenAndServe: ", err.String())
	}
}
开发者ID:stampzilla,项目名称:stampzilla,代码行数:7,代码来源:jonaz.go

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: main

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

示例13: ListenAndServe

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

示例14: httpRunner

// HTTP listner
func httpRunner() {
	http.HandleFunc("/", PushServer)
	err := http.ListenAndServe(":12345", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err.String())
	}
}
开发者ID:stampzilla,项目名称:stampzilla,代码行数:8,代码来源:buffer.go

示例15: main

func main() {
	http.HandleFunc("/", ProxyServer)
	err := http.ListenAndServe(":8123", nil)
	if err != nil {
		log.Exit("ListenAndServe: ", err.String())
	}
}
开发者ID:davecheney,项目名称:poxy,代码行数:7,代码来源:main.go


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