go-tsviewer/service/service.go

34 lines
611 B
Go
Raw 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 {
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
}