tsviewer/service/service.go

37 lines
702 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 {
TSClient *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
}
if err := client.UsePort(int(config.Server.Port)); err != nil {
return nil, err
}
return &Service{
TSClient: client,
}, nil
}