package service import ( "errors" "git.cliffbreak.de/haveachin/go-tsviewer/features/channel" "github.com/multiplay/go-ts3" ) func (s Service) Channel(id int) (*channel.Channel, error) { channels, err := s.TSClient.Server.ChannelList() if err != nil { return nil, err } var c *channel.Channel for _, channel := range channels { if channel.ID == id { c = convertChannel(channel) break } } if c == nil { return nil, errors.New("channel does not exist") } return c, nil } func (s Service) Channels() ([]*channel.Channel, error) { channels, err := s.TSClient.Server.ChannelList() if err != nil { return nil, err } var cc []*channel.Channel for _, channel := range channels { if channel.ParentID == 0 { cc = append(cc, convertChannel(channel)) continue } for _, c := range cc { if c.ID == channel.ParentID { c.Subchannels = append(c.Subchannels, *convertChannel(channel)) } } } return cc, nil } func convertChannel(c *ts3.Channel) *channel.Channel { return &channel.Channel{ ID: c.ID, Subchannels: []channel.Channel{}, Name: c.ChannelName, TotalClients: c.TotalClients, NeededSubscribePower: c.NeededSubscribePower, } }