mirror of
https://github.com/kataras/iris.git
synced 2025-03-13 21:36:28 +01: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:
parent
2042fddb66
commit
254a4ede95
|
@ -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
|
||||
|
|
|
@ -4,8 +4,11 @@ import "reflect"
|
|||
|
||||
var emptyIn = []reflect.Value{}
|
||||
|
||||
// IsZero returns true if a value is nil, remember boolean's false is zero.
|
||||
// IsZero returns true if a value is nil.
|
||||
// Remember; fields to be checked should be exported otherwise it returns false.
|
||||
// Notes for users:
|
||||
// Boolean's zero value is false, even if not set-ed.
|
||||
// UintXX are not zero on 0 because they are pointers to.
|
||||
func IsZero(v reflect.Value) bool {
|
||||
switch v.Kind() {
|
||||
case reflect.Struct:
|
||||
|
|
Loading…
Reference in New Issue
Block a user