mirror of
https://github.com/jech/galene.git
synced 2024-11-23 00:55:58 +01:00
Implement ranging over groups.
This commit is contained in:
parent
fb02c6fe1f
commit
22c6ad6b8c
2 changed files with 21 additions and 12 deletions
26
group.go
26
group.go
|
@ -123,14 +123,25 @@ func addGroup(name string, desc *groupDescription) (*group, error) {
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupNames() []string {
|
func rangeGroups(f func(g *group) bool) {
|
||||||
groups.mu.Lock()
|
groups.mu.Lock()
|
||||||
defer groups.mu.Unlock()
|
defer groups.mu.Unlock()
|
||||||
|
|
||||||
names := make([]string, 0, len(groups.groups))
|
for _, g := range groups.groups {
|
||||||
for name := range groups.groups {
|
ok := f(g)
|
||||||
names = append(names, name)
|
if !ok {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupNames() []string {
|
||||||
|
names := make([]string, 0)
|
||||||
|
|
||||||
|
rangeGroups(func(g *group) bool {
|
||||||
|
names = append(names, g.name)
|
||||||
|
return true
|
||||||
|
})
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,16 +419,15 @@ type publicGroup struct {
|
||||||
|
|
||||||
func getPublicGroups() []publicGroup {
|
func getPublicGroups() []publicGroup {
|
||||||
gs := make([]publicGroup, 0)
|
gs := make([]publicGroup, 0)
|
||||||
groups.mu.Lock()
|
rangeGroups(func (g *group) bool {
|
||||||
defer groups.mu.Unlock()
|
|
||||||
for _, g := range groups.groups {
|
|
||||||
if g.description.Public {
|
if g.description.Public {
|
||||||
gs = append(gs, publicGroup{
|
gs = append(gs, publicGroup{
|
||||||
Name: g.name,
|
Name: g.name,
|
||||||
ClientCount: len(g.clients),
|
ClientCount: len(g.clients),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
sort.Slice(gs, func(i, j int) bool {
|
sort.Slice(gs, func(i, j int) bool {
|
||||||
return gs[i].Name < gs[j].Name
|
return gs[i].Name < gs[j].Name
|
||||||
})
|
})
|
||||||
|
|
|
@ -47,11 +47,10 @@ func webserver() {
|
||||||
IdleTimeout: 120 * time.Second,
|
IdleTimeout: 120 * time.Second,
|
||||||
}
|
}
|
||||||
server.RegisterOnShutdown(func() {
|
server.RegisterOnShutdown(func() {
|
||||||
groups.mu.Lock()
|
rangeGroups(func (g *group) bool {
|
||||||
defer groups.mu.Unlock()
|
|
||||||
for _, g := range groups.groups {
|
|
||||||
go g.shutdown("server is shutting down")
|
go g.shutdown("server is shutting down")
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
})
|
})
|
||||||
go func() {
|
go func() {
|
||||||
var err error
|
var err error
|
||||||
|
|
Loading…
Reference in a new issue