styx/balboa/client.go
2020-02-10 16:11:25 +01:00

38 lines
696 B
Go

package balboa
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
// Client for Balboa instance.
type Client struct {
addr string
}
// NewClient for Balboa located at address.
func NewClient(address string) (c *Client) {
c = &Client{
addr: address,
}
return
}
// GetClient returns the cached session to Balboa. If no cached session
// is available, or when it is not valid any longer, a new session is
// created.
func GetClient() (*Client, error) {
logrus.Debugf("Getting new Balboa Client")
addr := viper.GetString("balboa.url")
if addr == "" {
return nil, fmt.Errorf("missing Balboa configuration")
}
client := NewClient(addr)
return client, nil
}