1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00

add explanation why the 'globalVisitorsController' example is a Singleton, because it was not clear for new gophers previously.

Former-commit-id: 9267c415e53eeb00adadf6fde9e0aeeb415cf24a
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-12-20 18:09:31 +02:00
parent 2042fddb66
commit 254a4ede95
2 changed files with 12 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ import (
func main() {
app := iris.New()
mvc.New(app.Party("/")).Register(new(globalVisitorsController))
mvc.New(app.Party("/")).Register(&globalVisitorsController{visits: 0})
// http://localhost:8080
app.Run(iris.Addr(":8080"))
@@ -18,10 +18,13 @@ func main() {
type globalVisitorsController struct {
// When a singleton controller is used then concurent safe access is up to the developers, because
// all clients share the same controller instance instead. Note that any controller's methods
// are per-client, but the struct's field can be shared accross multiple clients if the structure
// does not have any dynamic struct field depenendies that depend on the iris.Context,
// this declares a Singleton, note that you don't have to write a single line of code to do this, Iris is smart enough.
// all clients share the same controller instance instead.
// Note that any controller's methods
// are per-client, but the struct's field can be shared across multiple clients if the structure
// does not have any dynamic struct field depenendies that depend on the iris.Context
// and ALL field's values are NOT zero, at this case we use uint64 which it's no zero (even if we didn't set it
// manually ease-of-understand reasons) because it's a value of &{0}.
// All the above declares a Singleton, note that you don't have to write a single line of code to do this, Iris is smart enough.
//
// see `Get`.
visits uint64