Remove debug
This commit is contained in:
parent
66ab75eb69
commit
bb203a081c
@ -2,7 +2,6 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"github.com/TicketsBot/GoPanel/database"
|
"github.com/TicketsBot/GoPanel/database"
|
||||||
"github.com/TicketsBot/GoPanel/rpc/cache"
|
"github.com/TicketsBot/GoPanel/rpc/cache"
|
||||||
"github.com/TicketsBot/GoPanel/utils"
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
@ -12,7 +11,7 @@ import (
|
|||||||
"github.com/rxdn/gdl/objects/guild"
|
"github.com/rxdn/gdl/objects/guild"
|
||||||
"github.com/rxdn/gdl/rest/request"
|
"github.com/rxdn/gdl/rest/request"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"strings"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type wrappedGuild struct {
|
type wrappedGuild struct {
|
||||||
@ -84,45 +83,24 @@ func GetGuilds(ctx *gin.Context) {
|
|||||||
|
|
||||||
adminGuilds := make([]wrappedGuild, 0)
|
adminGuilds := make([]wrappedGuild, 0)
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
adminGuilds := make([]wrappedGuild, 0)
|
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-wg.Wait():
|
case <-wg.Wait():
|
||||||
break loop
|
break loop
|
||||||
case guild := <-ch:
|
case guild := <-ch:
|
||||||
// Sort by name
|
|
||||||
var index int
|
|
||||||
for i, el := range adminGuilds {
|
|
||||||
fmt.Printf("%s %s %v\n", guild.Name, el.Name, guild.Name < el.Name)
|
|
||||||
if strings.ToLower(guild.Name) < strings.ToLower(el.Name) {
|
|
||||||
index = i
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if index >= len(adminGuilds) {
|
|
||||||
adminGuilds = append(adminGuilds, guild)
|
adminGuilds = append(adminGuilds, guild)
|
||||||
} else {
|
|
||||||
adminGuilds = append(adminGuilds, wrappedGuild{}) // create extra capacity with zero value
|
|
||||||
copy(adminGuilds[index+1:], adminGuilds[index:])
|
|
||||||
adminGuilds[index] = guild
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// not possible anyway but eh
|
_ = group.Wait() // error not possible
|
||||||
if err := group.Wait(); err != nil {
|
|
||||||
ctx.JSON(500, gin.H{
|
// sort
|
||||||
"success": false,
|
sort.Slice(adminGuilds, func(i, j int) bool {
|
||||||
"error": err.Error(),
|
return adminGuilds[i].Name < adminGuilds[j].Name
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.JSON(200, adminGuilds)
|
ctx.JSON(200, adminGuilds)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user