add PartyFunc and gofmt -s -w . 🔷

Former-commit-id: a3809498a45140d691f3f235ad9cb25239d495a2
This commit is contained in:
hiveminded 2017-08-01 22:25:08 +03:00
parent 351f099ad6
commit 9143ccec6e
8 changed files with 73 additions and 8 deletions

View File

@ -15,7 +15,8 @@ after_script:
- cd ./_examples
- go get ./...
- go test -v -cover ./...
- cd ../
# typescript examples
- cd ../../typescript/_examples
- cd ./typescript/_examples
- go get ./...
- go test -v -cover ./...

View File

@ -41,6 +41,12 @@ type ResponseRecorder struct {
var _ ResponseWriter = &ResponseRecorder{}
// Naive returns the simple, underline and original http.ResponseWriter
// that backends this response writer.
func (w *ResponseRecorder) Naive() http.ResponseWriter {
return w.ResponseWriter.Naive()
}
// BeginRecord accepts its parent ResponseWriter and
// prepares itself, the response recorder, to record and send response to the client.
func (w *ResponseRecorder) BeginRecord(underline ResponseWriter) {

View File

@ -28,6 +28,10 @@ type ResponseWriter interface {
http.CloseNotifier
http.Pusher
// Naive returns the simple, underline and original http.ResponseWriter
// that backends this response writer.
Naive() http.ResponseWriter
// BeginResponse receives an http.ResponseWriter
// and initialize or reset the response writer's field's values.
BeginResponse(http.ResponseWriter)
@ -117,6 +121,12 @@ const (
StatusCodeWritten = 0
)
// Naive returns the simple, underline and original http.ResponseWriter
// that backends this response writer.
func (w *responseWriter) Naive() http.ResponseWriter {
return w.ResponseWriter
}
// BeginResponse receives an http.ResponseWriter
// and initialize or reset the response writer's field's values.
func (w *responseWriter) BeginResponse(underline http.ResponseWriter) {

View File

@ -215,6 +215,28 @@ func (rb *APIBuilder) Party(relativePath string, handlers ...context.Handler) Pa
}
}
// PartyFunc same as `Party`, groups routes that share a base path or/and same handlers.
// However this function accepts a function that receives this created Party instead.
// Returns the Party in order the caller to be able to use this created Party to continue the
// top-bottom routes "tree".
//
// Note: `iris#Party` and `core/router#Party` describes the exactly same interface.
//
// Usage:
// app.PartyFunc("/users", func(u iris.Party){
// u.Use(authMiddleware, logMiddleware)
// u.Get("/", getAllUsers)
// u.Post("/", createOrUpdateUser)
// u.Delete("/", deleteUser)
// })
//
// Look `Party` for more.
func (rb *APIBuilder) PartyFunc(relativePath string, partyBuilderFunc func(p Party)) Party {
p := rb.Party(relativePath)
partyBuilderFunc(p)
return p
}
// Subdomain returns a new party which is responsible to register routes to
// this specific "subdomain".
//

View File

@ -2,7 +2,9 @@ package router
import (
"github.com/kataras/iris/context"
) // Party is here to separate the concept of
)
// Party is here to separate the concept of
// api builder and the sub api builder.
// Party is just a group joiner of routes which have the same prefix and share same middleware(s) also.
@ -12,6 +14,23 @@ import (
type Party interface {
// Party creates and returns a new child Party with the following features.
Party(relativePath string, middleware ...context.Handler) Party
// PartyFunc same as `Party`, groups routes that share a base path or/and same handlers.
// However this function accepts a function that receives this created Party instead.
// Returns the Party in order the caller to be able to use this created Party to continue the
// top-bottom routes "tree".
//
// Note: `iris#Party` and `core/router#Party` describes the exactly same interface.
//
// Usage:
// app.PartyFunc("/users", func(u iris.Party){
// u.Use(authMiddleware, logMiddleware)
// u.Get("/", getAllUsers)
// u.Post("/", createOrUpdateUser)
// u.Delete("/", deleteUser)
// })
//
// Look `Party` for more.
PartyFunc(relativePath string, partyBuilderFunc func(p Party)) Party
// Subdomain returns a new party which is responsible to register routes to
// this specific "subdomain".
//

View File

@ -276,6 +276,13 @@ func (app *Application) View(writer io.Writer, filename string, layout string, b
}
var (
// Party is just a group joiner of routes which have the same prefix and share same middleware(s) also.
// Party could also be named as 'Join' or 'Node' or 'Group' , Party chosen because it is fun.
//
// Look the `core/router#APIBuilder` for its implementation.
//
// A shortcut for the `core/router#Party`, useful when `PartyFunc` is being used.
Party router.Party
// LimitRequestBodySize is a middleware which sets a request body size limit
// for all next handlers in the chain.
//

View File

@ -25,11 +25,11 @@ type (
// but without temp values (flash messages) which are removed after fetching.
// so introduce a new field here.
// NOTE: flashes are not managed by third-party, only inside session struct.
flashes map[string]*flashMessage
mu sync.RWMutex
expireAt *time.Time // nil pointer means no expire date
timer *time.Timer
provider *provider
flashes map[string]*flashMessage
mu sync.RWMutex
expireAt *time.Time // nil pointer means no expire date
timer *time.Timer
provider *provider
}
flashMessage struct {

View File

@ -1,9 +1,9 @@
package redis
import (
"time"
"bytes"
"encoding/gob"
"time"
"github.com/kataras/iris/sessions/sessiondb/redis/service"
)