go-tsviewer/service/service.go
2019-01-17 01:35:51 +01:00

41 lines
739 B
Go

package service
import (
"fmt"
"log"
"time"
"git.cliffbreak.de/Cliffbreak/tsviewer/config"
ts3 "github.com/multiplay/go-ts3"
)
type Service struct {
TSClient *ts3.Client
}
func New(config config.Config) (*Service, error) {
client, err := ts3.NewClient(fmt.Sprintf("%s:%d", config.ServerTS.IP, config.ServerTS.PortQuery))
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.ServerTS.PortServer)); err != nil {
return nil, err
}
go func() {
for true {
time.Sleep(time.Second * 150)
client.Server.Version()
log.Println("keep alive")
}
}()
return &Service{
TSClient: client,
}, nil
}