This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Directory will return a map of all people stored within the Directory. | |
func (d *Directory) Directory() map[string]Person { | |
d.RLock() | |
defer d.RUnlock() | |
m := make(map[string]Person) | |
for k, v := range d.directory { | |
m[k] = v | |
} | |
return m | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Directory will return a map of all people stored within the Directory. | |
func (d *Directory) Directory() map[string]Person { | |
d.RLock() | |
defer d.RUnlock() | |
return d.directory | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name will return the current Directory name. | |
func (d *Directory) Name() string { | |
d.RLock() | |
defer d.RUnlock() | |
return d.name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SetName will change the name of the current Directory. | |
func (d *Directory) SetName(n string) error { | |
if n == "" { | |
return fmt.Errorf("cannot have an empty name") | |
} | |
d.Lock() | |
defer d.Unlock() | |
d.name = n | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Directory provides the ability to store and lookup people. | |
type Directory struct { | |
sync.RWMutex | |
// directory stores known People | |
directory map[string]Person | |
// name is used to identify the Directory instance | |
name string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
"sync" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http.HandleFunc("/count", func(w http.ResponseWriter, r *http.Request) { | |
counter = counter + 1 | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Package directory is an example package that creates an internal directory for People. | |
This package is an example used for a Blog article and is not for anything else. | |
*/ | |
package directory | |
import ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Package directory is an example package that creates an internal directory for People. | |
This package is an example used for a Blog article and is not for anything else. | |
*/ | |
package directory | |
import ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// New is used to create a new instance of Directory. | |
func New(name string) (*Directory, error) { | |
return &Directory{}, nil | |
} |
NewerOlder