mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 05:26:26 +01:00
Multiserver listening - Try first for https://github.com/kataras/iris/issues/235 - example added
This commit is contained in:
parent
9d8f32ce1a
commit
5b8f4dc1b0
2
http.go
2
http.go
|
@ -410,7 +410,7 @@ func (s *Server) Open() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// close closes the server
|
// close closes the server
|
||||||
func (s *Server) close() (err error) {
|
func (s *Server) Close() (err error) {
|
||||||
if !s.IsListening() {
|
if !s.IsListening() {
|
||||||
return errServerIsClosed.Return()
|
return errServerIsClosed.Return()
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ func (s *Framework) openServer() (err error) {
|
||||||
// closeServer is used to close the tcp listener from the server, returns an error
|
// closeServer is used to close the tcp listener from the server, returns an error
|
||||||
func (s *Framework) closeServer() error {
|
func (s *Framework) closeServer() error {
|
||||||
s.Plugins.DoPreClose(s)
|
s.Plugins.DoPreClose(s)
|
||||||
return s.HTTPServer.close()
|
return s.HTTPServer.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// justServe initializes the whole framework but server doesn't listens to a specific net.Listener
|
// justServe initializes the whole framework but server doesn't listens to a specific net.Listener
|
||||||
|
|
50
iris.go
50
iris.go
|
@ -90,6 +90,7 @@ type (
|
||||||
ListenUNIXWithErr(string, os.FileMode) error
|
ListenUNIXWithErr(string, os.FileMode) error
|
||||||
ListenUNIX(string, os.FileMode)
|
ListenUNIX(string, os.FileMode)
|
||||||
NoListen() *Server
|
NoListen() *Server
|
||||||
|
ListenToServer(config.Server) (*Server, error)
|
||||||
Close()
|
Close()
|
||||||
// global middleware prepending, registers to all subdomains, to all parties, you can call it at the last also
|
// global middleware prepending, registers to all subdomains, to all parties, you can call it at the last also
|
||||||
MustUse(...Handler)
|
MustUse(...Handler)
|
||||||
|
@ -553,6 +554,55 @@ func (s *Framework) TemplateString(templateFile string, pageContext interface{},
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListenToServer starts a 'secondary' server which listens to this station
|
||||||
|
// this server will not be the main server (unless it's the first listen)
|
||||||
|
// Note that the view engine's functions {{ url }} and {{ urlpath }} will return the first's registered server's scheme (http/https)
|
||||||
|
//
|
||||||
|
// this is useful only when you want to have two listen ports ( two servers ) for the same station
|
||||||
|
//
|
||||||
|
// receives one parameter which is the config.Server for the new server
|
||||||
|
// returns the new standalone server( you can close this server by this reference) and an error
|
||||||
|
//
|
||||||
|
// If you have only one scheme this function is useless for you, instead you can use the normal .Listen/ListenTLS functions.
|
||||||
|
//
|
||||||
|
// this is a blocking version, like .Listen/ListenTLS
|
||||||
|
func ListenToServer(cfg config.Server) (*Server, error) {
|
||||||
|
return Default.ListenToServer(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListenToServer starts a server which listens to this station
|
||||||
|
// Note that the view engine's functions {{ url }} and {{ urlpath }} will return the first's registered server's scheme (http/https)
|
||||||
|
//
|
||||||
|
// this is useful only when you want to have two listen ports ( two servers ) for the same station
|
||||||
|
//
|
||||||
|
// receives one parameter which is the config.Server for the new server
|
||||||
|
// returns the new standalone server( you can close this server by this reference) and an error
|
||||||
|
//
|
||||||
|
// If you have only one scheme this function is useless for you, instead you can use the normal .Listen/ListenTLS functions.
|
||||||
|
//
|
||||||
|
// this is a blocking version, like .Listen/ListenTLS
|
||||||
|
func (s *Framework) ListenToServer(cfg config.Server) (*Server, error) {
|
||||||
|
time.Sleep(time.Duration(3) * time.Second) // yes we wait, so simple, because the previous will run on goroutine
|
||||||
|
// if the main server is not yet started, then this is the main server
|
||||||
|
// although this function should not be used to Listen to the main server, but if so then do it right:
|
||||||
|
if !s.HTTPServer.IsListening() {
|
||||||
|
println("samae server")
|
||||||
|
s.HTTPServer.Config = &cfg
|
||||||
|
err := s.openServer()
|
||||||
|
return s.HTTPServer, err
|
||||||
|
}
|
||||||
|
|
||||||
|
srv := newServer(&cfg)
|
||||||
|
srv.Handler = s.HTTPServer.Handler
|
||||||
|
err := srv.Open()
|
||||||
|
if err == nil {
|
||||||
|
ch := make(chan os.Signal)
|
||||||
|
<-ch
|
||||||
|
srv.Close()
|
||||||
|
}
|
||||||
|
return srv, err
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
// ----------------------------------MuxAPI implementation------------------------------
|
// ----------------------------------MuxAPI implementation------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user