本文整理汇总了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{})
}
示例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())
}
}
示例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)
}
}
示例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)
}
}
示例5: main
func main() {
http.HandleFunc("/", handler)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}
示例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
}
示例7: main
func main() {
http.Handle("/", http.HandlerFunc(PushServer))
err := http.ListenAndServe(":12345", nil)
if err != nil {
panic("ListenAndServe: ", err.String())
}
}
示例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)
}
}
示例9: main
func main() {
http.HandleFunc("/view/", viewHandler)
http.HandleFunc("/edit/", editHandler)
http.HandleFunc("/save/", saveHandler)
http.ListenAndServe(":8080", nil)
}
示例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)
}
示例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)
}
示例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()
}
示例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())
}
}
示例14: httpRunner
// HTTP listner
func httpRunner() {
http.HandleFunc("/", PushServer)
err := http.ListenAndServe(":12345", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.String())
}
}
示例15: main
func main() {
http.HandleFunc("/", ProxyServer)
err := http.ListenAndServe(":8123", nil)
if err != nil {
log.Exit("ListenAndServe: ", err.String())
}
}