go-tsviewer/service/service.go

38 lines
702 B
Go
Raw Permalink Normal View History

2019-01-14 20:07:11 +00:00
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 {
2019-01-15 00:46:39 +00:00
TSClient *ts3.Client
2019-01-14 20:07:11 +00:00
}
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
}
2019-01-15 00:46:39 +00:00
if err := client.UsePort(int(config.Server.Port)); err != nil {
return nil, err
}
2019-01-14 20:07:11 +00:00
return &Service{
2019-01-15 00:46:39 +00:00
TSClient: client,
2019-01-14 20:07:11 +00:00
}, nil
}