Move utility functions down
This commit is contained in:
parent
7f4eb2e7e3
commit
b0fb1b5bec
|
|
@ -206,28 +206,6 @@ func (b *memoryBackend) ChannelsGetList() ([]microsub.Channel, error) {
|
||||||
return channels, nil
|
return channels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *memoryBackend) createChannel(name string) microsub.Channel {
|
|
||||||
uid := fmt.Sprintf("%012d", b.NextUid)
|
|
||||||
channel := microsub.Channel{
|
|
||||||
UID: uid,
|
|
||||||
Name: name,
|
|
||||||
}
|
|
||||||
return channel
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *memoryBackend) setChannel(channel microsub.Channel) {
|
|
||||||
b.lock.Lock()
|
|
||||||
defer b.lock.Unlock()
|
|
||||||
b.Channels[channel.UID] = channel
|
|
||||||
b.Feeds[channel.UID] = []microsub.Feed{}
|
|
||||||
b.NextUid++
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateChannelInRedis(conn redis.Conn, uid string, prio int) {
|
|
||||||
conn.Do("SADD", "channels", uid)
|
|
||||||
conn.Do("SETNX", "channel_sortorder_"+uid, prio)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChannelsCreate creates a channels
|
// ChannelsCreate creates a channels
|
||||||
func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) {
|
func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) {
|
||||||
defer b.save()
|
defer b.save()
|
||||||
|
|
@ -267,11 +245,6 @@ func (b *memoryBackend) ChannelsUpdate(uid, name string) (microsub.Channel, erro
|
||||||
return microsub.Channel{}, fmt.Errorf("Channel %s does not exist", uid)
|
return microsub.Channel{}, fmt.Errorf("Channel %s does not exist", uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeChannelFromRedis(conn redis.Conn, uid string) {
|
|
||||||
conn.Do("SREM", "channels", uid)
|
|
||||||
conn.Do("DEL", "channel_sortorder_"+uid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChannelsDelete deletes a channel
|
// ChannelsDelete deletes a channel
|
||||||
func (b *memoryBackend) ChannelsDelete(uid string) error {
|
func (b *memoryBackend) ChannelsDelete(uid string) error {
|
||||||
defer b.save()
|
defer b.save()
|
||||||
|
|
@ -854,3 +827,30 @@ func (b *memoryBackend) AddEventListener(el microsub.EventListener) error {
|
||||||
b.listeners = append(b.listeners, el)
|
b.listeners = append(b.listeners, el)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *memoryBackend) createChannel(name string) microsub.Channel {
|
||||||
|
uid := fmt.Sprintf("%012d", b.NextUid)
|
||||||
|
channel := microsub.Channel{
|
||||||
|
UID: uid,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
return channel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *memoryBackend) setChannel(channel microsub.Channel) {
|
||||||
|
b.lock.Lock()
|
||||||
|
defer b.lock.Unlock()
|
||||||
|
b.Channels[channel.UID] = channel
|
||||||
|
b.Feeds[channel.UID] = []microsub.Feed{}
|
||||||
|
b.NextUid++
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateChannelInRedis(conn redis.Conn, uid string, prio int) {
|
||||||
|
conn.Do("SADD", "channels", uid)
|
||||||
|
conn.Do("SETNX", "channel_sortorder_"+uid, prio)
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeChannelFromRedis(conn redis.Conn, uid string) {
|
||||||
|
conn.Do("SREM", "channels", uid)
|
||||||
|
conn.Do("DEL", "channel_sortorder_"+uid)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user