Available is never returns false, just re-allocate on .Close - test https://github.com/iris-contrib/tests/blob/master/server_test.go

This commit is contained in:
Makis Maropoulos 2016-07-03 02:01:48 +02:00
parent 160b8d9545
commit 1354b74822
4 changed files with 25 additions and 23 deletions

View File

@ -26,7 +26,7 @@ var (
Websocket websocket.Server
HTTPServer *Server
// Available is a channel type of bool, fired to true when the server is opened and all plugins ran
// fires false when .Close is called manually.
// never fires false, if the .Close called then the channel is re-allocating.
// the channel is always oepen until you close it when you don't need this.
//
// Note: it is a simple channel and decided to put it here and no inside HTTPServer, doesn't have statuses just true and false, simple as possible
@ -189,7 +189,7 @@ func (s *Framework) openServer() (err error) {
// closeServer is used to close the tcp listener from the server, returns an error
func (s *Framework) closeServer() error {
s.Plugins.DoPreClose(s)
s.Available <- false
s.Available = make(chan bool)
return s.HTTPServer.Close()
}

View File

@ -123,7 +123,7 @@ func (e *Engine) ExecuteWriter(out io.Writer, name string, binding interface{},
isLayout := false
renderFilename := name
if layout != "" && layout != config.NoLayout {
if layout != "" {
isLayout = true
renderFilename = layout // the render becomes the layout, and the name is the partial.
}

View File

@ -233,7 +233,7 @@ func (s *Engine) runtimeFuncsFor(name string, binding interface{}) {
// ExecuteWriter executes a templates and write its results to the out writer
func (s *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error {
if layout != "" && layout != config.NoLayout {
if layout != "" {
s.layoutFuncsFor(name, binding)
name = layout

View File

@ -148,6 +148,25 @@ func RegisterSharedFuncs(theFuncs map[string]interface{}) {
}
func (t *Template) getLayout(ctx context.IContext, passedLayouts []string) string {
_layout := ""
if len(passedLayouts) > 0 {
_layout = passedLayouts[0]
} else if ctx != nil {
if layoutFromCtx := ctx.GetString(config.TemplateLayoutContextKey); layoutFromCtx != "" {
_layout = layoutFromCtx
}
}
if _layout == "" && _layout != config.NoLayout {
if t.Layout != config.NoLayout { // the config's Layout is disabled if "" , config.NoLayout should be passed only on ctx.Render but for any case check if user set it as config.NoLayout also
_layout = t.Layout
}
}
return _layout
}
// Render renders a template using the context's writer
func (t *Template) Render(ctx context.IContext, name string, binding interface{}, layout ...string) (err error) {
@ -163,18 +182,8 @@ func (t *Template) Render(ctx context.IContext, name string, binding interface{}
}
}
// I don't like this, something feels wrong
_layout := ""
if len(layout) > 0 {
_layout = layout[0]
} else if layoutFromCtx := ctx.GetString(config.TemplateLayoutContextKey); layoutFromCtx != "" {
_layout = layoutFromCtx
}
if _layout == "" {
_layout = t.Layout
}
_layout := t.getLayout(ctx, layout)
//
ctx.GetRequestCtx().Response.Header.Set("Content-Type", t.ContentType)
var out io.Writer
@ -209,14 +218,7 @@ func (t *Template) RenderString(name string, binding interface{}, layout ...stri
}
}
// I don't like this, something feels wrong
_layout := ""
if len(layout) > 0 {
_layout = layout[0]
}
if _layout == "" {
_layout = t.Layout
}
_layout := t.getLayout(nil, layout)
out := t.buffer.Get()
// if we have problems later consider that -> out.Reset()