Skip to content

Commit

Permalink
####Version0.3.21
Browse files Browse the repository at this point in the history
* dotweb.DotWeb.ListenAndServer(addr string) 支持原生host监听
* dotweb.Context增加Context() & SetTimeoutContext() & WithContext()
* dotweb.Request增加自动生成unique RequestID,通过RequestID()获取,默认置入dotweb.Context.context中,以RequestID为key
* dotweb.DotWeb增加Close()、Shutdown()
2017-06-14 23:30
  • Loading branch information
[email protected] authored and zouyixian committed Jun 15, 2017
1 parent 8fb1c69 commit 530de92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dotweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

"context"
"errors"
"github.com/devfeel/dotweb/cache"
"github.com/devfeel/dotweb/config"
Expand Down Expand Up @@ -349,7 +350,7 @@ func (app *DotWeb) ListenAndServe(addr string) error {
}

logger.Logger().Log("Dotweb:ListenAndServe["+addr+"] begin", LogTarget_HttpServer, LogLevel_Debug)
err := http.ListenAndServe(addr, app.HttpServer)
err := app.HttpServer.ListenAndServe(addr)
return err
}

Expand Down Expand Up @@ -382,6 +383,18 @@ func (ds *DotWeb) DefaultHTTPErrorHandler(ctx Context, err error) {
}
}

// Close immediately stops the server.
// It internally calls `http.Server#Close()`.
func (ds *DotWeb) Close() error {
return ds.HttpServer.stdServer.Close()
}

// Shutdown stops server the gracefully.
// It internally calls `http.Server#Shutdown()`.
func (ds *DotWeb) Shutdown(ctx context.Context) error {
return ds.HttpServer.stdServer.Shutdown(ctx)
}

// init inner routers
func initInnerRouter(server *HttpServer) {
//默认支持pprof信息查看
Expand Down
9 changes: 9 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type (

//HttpServer定义
HttpServer struct {
stdServer *http.Server
router Router
DotApp *DotWeb
sessionManager *session.SessionManager
Expand Down Expand Up @@ -86,9 +87,17 @@ func NewHttpServer() *HttpServer {
}
//设置router
server.router = NewRouter(server)
server.stdServer = &http.Server{Handler: server}
return server
}

// ListenAndServe listens on the TCP network address srv.Addr and then
// calls Serve to handle requests on incoming connections.
func (server *HttpServer) ListenAndServe(addr string) error {
server.stdServer.Addr = addr
return server.stdServer.ListenAndServe()
}

// ServeHTTP make sure request can be handled correctly
func (server *HttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
//针对websocket与调试信息特殊处理
Expand Down

0 comments on commit 530de92

Please sign in to comment.