34 lines
611 B
Go
34 lines
611 B
Go
|
package service
|
||
|
|
||
|
import (
|
||
|
"strconv"
|
||
|
|
||
|
"git.cliffbreak.de/haveachin/go-tsviewer/config"
|
||
|
"git.cliffbreak.de/haveachin/go-tsviewer/stringer"
|
||
|
ts3 "github.com/multiplay/go-ts3"
|
||
|
)
|
||
|
|
||
|
type Service struct {
|
||
|
Client *ts3.Client
|
||
|
}
|
||
|
|
||
|
func New(config config.Config) (*Service, error) {
|
||
|
addr, err := stringer.Build(config.IP, ":", strconv.Itoa(int(config.Port)))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
client, err := ts3.NewClient(addr)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
if err := client.Login(config.User.Name, config.User.Password); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &Service{
|
||
|
Client: client,
|
||
|
}, nil
|
||
|
}
|