新增httpserver

This commit is contained in:
boyce
2019-01-26 14:21:16 +08:00
parent 674ecae76e
commit 7818c69a68

36
network/httpserver.go Normal file
View File

@@ -0,0 +1,36 @@
package network
import (
"fmt"
"net/http"
)
type HttpServer struct {
port uint16
}
func (slf *HttpServer) Init(port uint16) {
slf.port = port
}
func (slf *HttpServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) {
http.HandleFunc(pattern, handler)
}
func (slf *HttpServer) Start() {
go slf.startListen()
}
func (slf *HttpServer) startListen() error {
listenPort := fmt.Sprintf(":%d", slf.port)
err := http.ListenAndServe(listenPort, nil)
if err != nil {
fmt.Printf("http.ListenAndServe(%d, nil) error\n", slf.port)
}
return nil
}
func (slf *WebsocketServer) Stop() {
}