diff --git a/DONATIONS.md b/DONATIONS.md index 72b1dda6..56b5096d 100644 --- a/DONATIONS.md +++ b/DONATIONS.md @@ -50,6 +50,8 @@ I'm grateful for all the generous donations. Iris is fully funded by these dona - ANONYMOUS donated 5 EUR at December 13 +- [Github username is not available yet] donated 25 EUR at Jenuary 8 of 2017 + > * The name or/and github username link added after donator's approvement via e-mail. #### Report, so far @@ -58,5 +60,5 @@ I'm grateful for all the generous donations. Iris is fully funded by these dona - **Thanks** to all of **You**, 424 EUR donated to [Holy Metropolis of Ioannina](http://www.imioanninon.gr/main/) for clothes, foods and medications for our fellow human beings. -**Available**: VAT(50) + VAT(20) + VAT(20) + VAT(50) + VAT(6) + VAT(20) + VAT(100) + VAT(20) + VAT(20) + VAT(50) + VAT(30) + VAT(50) + VAT(20) + VAT(5) - 13 = 47,45 + 18,97 + 18,61 + 47,05 + 5,34 + 18,97 + 98,04 + 18,97 + 18,61 + 47,95 + 28,24 + 47,05 + 18,97 + 4,59 - 13 - 424 = -424,92 EUR - 424 = **0,92** +**Available**: VAT(50) + VAT(20) + VAT(20) + VAT(50) + VAT(6) + VAT(20) + VAT(100) + VAT(20) + VAT(20) + VAT(50) + VAT(30) + VAT(50) + VAT(20) + VAT(5) + VAT(25) - 13 = 47,45 + 18,97 + 18,61 + 47,05 + 5,34 + 18,97 + 98,04 + 18,97 + 18,61 + 47,95 + 28,24 + 47,05 + 18,97 + 4,59 + 23,80 - 13 - 424 = +424,92 - 424 = **24,72 EUR** diff --git a/README.md b/README.md index 47f0084a..73d755a6 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,14 @@ Built with GoLang - Cross framework - Donation
-CHANGELOG/HISTORY +CHANGELOG/HISTORY Examples @@ -647,6 +645,104 @@ DestroyAllSessions() ### Websockets +Server configuration + +```go +iris.Config.Websocket{ + // WriteTimeout time allowed to write a message to the connection. + // Default value is 15 * time.Second + WriteTimeout time.Duration + // PongTimeout allowed to read the next pong message from the connection + // Default value is 60 * time.Second + PongTimeout time.Duration + // PingPeriod send ping messages to the connection with this period. Must be less than PongTimeout + // Default value is (PongTimeout * 9) / 10 + PingPeriod time.Duration + // MaxMessageSize max message size allowed from connection + // Default value is 1024 + MaxMessageSize int64 + // BinaryMessages set it to true in order to denotes binary data messages instead of utf-8 text + // see https://github.com/kataras/iris/issues/387#issuecomment-243006022 for more + // Defaults to false + BinaryMessages bool + // Endpoint is the path which the websocket server will listen for clients/connections + // Default value is empty string, if you don't set it the Websocket server is disabled. + Endpoint string + // ReadBufferSize is the buffer size for the underline reader + ReadBufferSize int + // WriteBufferSize is the buffer size for the underline writer + WriteBufferSize int + // Error specifies the function for generating HTTP error responses. + // + // The default behavior is to store the reason in the context (ctx.Set(reason)) and fire any custom error (ctx.EmitError(status)) + Error func(ctx *Context, status int, reason error) + // CheckOrigin returns true if the request Origin header is acceptable. If + // CheckOrigin is nil, the host in the Origin header must not be set or + // must match the host of the request. + // + // The default behavior is to allow all origins + // you can change this behavior by setting the iris.Config.Websocket.CheckOrigin = iris.WebsocketCheckSameOrigin + CheckOrigin func(r *http.Request) bool + // IDGenerator used to create (and later on, set) + // an ID for each incoming websocket connections (clients). + // If empty then the ID is generated by the result of 64 + // random combined characters + IDGenerator func(r *http.Request) string +} + +``` + +Connection's methods + +```go +ID() string + +Request() *http.Request + +// Receive from the client +On("anyCustomEvent", func(message string) {}) +On("anyCustomEvent", func(message int){}) +On("anyCustomEvent", func(message bool){}) +On("anyCustomEvent", func(message anyCustomType){}) +On("anyCustomEvent", func(){}) + +// Receive a native websocket message from the client +// compatible without need of import the iris-ws.js to the .html +OnMessage(func(message []byte){}) + +// Send to the client +Emit("anyCustomEvent", string) +Emit("anyCustomEvent", int) +Emit("anyCustomEvent", bool) +Emit("anyCustomEvent", anyCustomType) + +// Send native websocket messages +// with config.BinaryMessages = true +// useful when you use proto or something like this. +EmitMessage([]byte("anyMessage")) + +// Send to specific client(s) +To("otherConnectionId").Emit/EmitMessage... +To("anyCustomRoom").Emit/EmitMessage... + +// Send to all opened connections/clients +To(websocket.All).Emit/EmitMessage... + +// Send to all opened connections/clients EXCEPT this client +To(websocket.Broadcast).Emit/EmitMessage... + +// Rooms, group of connections/clients +Join("anyCustomRoom") +Leave("anyCustomRoom") + + +// Fired when the connection is closed +OnDisconnect(func(){}) + +// Force-disconnect the client from the server-side +Disconnect() error +``` + ```go // file ./main.go package main @@ -847,7 +943,7 @@ I recommend writing your API tests using this new library, [httpexpect](https:// Versioning ------------ -Current: **v6.0.5** +Current: **v6.0.6** Stable: **[v5/fasthttp](https://github.com/kataras/iris/tree/5.0.0)** diff --git a/configuration.go b/configuration.go index f99a5d90..26c24109 100644 --- a/configuration.go +++ b/configuration.go @@ -606,10 +606,6 @@ type WebsocketConfiguration struct { ReadBufferSize int // WriteBufferSize is the buffer size for the underline writer WriteBufferSize int - // Headers if true then the client's headers are copy to the websocket connection - // - // Default is true - Headers bool // Error specifies the function for generating HTTP error responses. // // The default behavior is to store the reason in the context (ctx.Set(reason)) and fire any custom error (ctx.EmitError(status)) @@ -621,6 +617,11 @@ type WebsocketConfiguration struct { // The default behavior is to allow all origins // you can change this behavior by setting the iris.Config.Websocket.CheckOrigin = iris.WebsocketCheckSameOrigin CheckOrigin func(r *http.Request) bool + // IDGenerator used to create (and later on, set) + // an ID for each incoming websocket connections (clients). + // If empty then the ID is generated by the result of 64 + // random combined characters + IDGenerator func(r *http.Request) string } var ( @@ -679,12 +680,7 @@ var ( c.Websocket.WriteBufferSize = val } } - // OptionWebsocketHeaders if true then the client's headers are copy to the websocket connection - OptionWebsocketHeaders = func(val bool) OptionSet { - return func(c *Configuration) { - c.Websocket.Headers = val - } - } + // OptionWebsocketError specifies the function for generating HTTP error responses. OptionWebsocketError = func(val func(*Context, int, error)) OptionSet { return func(c *Configuration) { @@ -699,6 +695,16 @@ var ( c.Websocket.CheckOrigin = val } } + + // OptionWebsocketIDGenerator used to create (and later on, set) + // an ID for each incoming websocket connections (clients). + // If empty then the ID is generated by the result of 64 + // random combined characters + OptionWebsocketIDGenerator = func(val func(*http.Request) string) OptionSet { + return func(c *Configuration) { + c.Websocket.IDGenerator = val + } + } ) const ( @@ -748,7 +754,8 @@ func DefaultWebsocketConfiguration() WebsocketConfiguration { ReadBufferSize: 4096, WriteBufferSize: 4096, Endpoint: "", - Headers: true, + // use the kataras/go-websocket default + IDGenerator: nil, } } diff --git a/iris.go b/iris.go index 00361ce6..02957999 100644 --- a/iris.go +++ b/iris.go @@ -9,8 +9,8 @@ package main import "github.com/kataras/iris" func main() { - iris.Get("/hi_json", func(c *iris.Context) { - c.JSON(iris.StatusOK, iris.Map{ + iris.Get("/hi_json", func(ctx *iris.Context) { + ctx.JSON(iris.StatusOK, iris.Map{ "Name": "Iris", "Released": "13 March 2016", "Stars": "5883", @@ -27,8 +27,8 @@ import "github.com/kataras/iris" func main() { s1 := iris.New() - s1.Get("/hi_json", func(c *iris.Context) { - c.JSON(iris.StatusOK, iris.Map{ + s1.Get("/hi_json", func(ctx *iris.Context) { + ctx.JSON(iris.StatusOK, iris.Map{ "Name": "Iris", "Released": "13 March 2016", "Stars": "5883", @@ -36,8 +36,8 @@ func main() { }) s2 := iris.New() - s2.Get("/hi_raw_html", func(c *iris.Context) { - c.HTML(iris.StatusOK, " Iris welcomes

you!

") + s2.Get("/hi_raw_html", func(ctx *iris.Context) { + ctx.HTML(iris.StatusOK, " Iris welcomes

you!

") }) go s1.Listen(":8080") @@ -47,7 +47,7 @@ func main() { ---------------------------------------------------------------------- For middleware, template engines, response engines, sessions, websockets, mails, subdomains, -dynamic subdomains, routes, party of subdomains & routes, ssh and much more +dynamic subdomains, routes, party of subdomains & routes and more visit https://docs.iris-go.com */ @@ -81,7 +81,7 @@ const ( // IsLongTermSupport flag is true when the below version number is a long-term-support version IsLongTermSupport = false // Version is the current version number of the Iris web framework - Version = "6.0.5" + Version = "6.0.6" banner = ` _____ _ |_ _| (_) diff --git a/websocket.go b/websocket.go index 5f942e5b..df37dbbc 100644 --- a/websocket.go +++ b/websocket.go @@ -83,6 +83,7 @@ func (ws *WebsocketServer) init() { ws.station.ReleaseCtx(ctx) }, CheckOrigin: c.CheckOrigin, + IDGenerator: c.IDGenerator, }) }