Documentation ¶
Overview ¶
Package kodirpc is a JSON-RPC client for the TCP socket of the Kodi home theatre software.
Index ¶
Examples ¶
Constants ¶
const ( // DefaultReadTimeout is the default time a call will wait for a response. DefaultReadTimeout = 5 * time.Second // DefaultConnectTimeout is the default time re-/connection will be // attempted before failure. DefaultConnectTimeout = 5 * time.Minute // DefaultReconnect determines whether the client reconnects by default. DefaultReconnect = true // DefaultConnectBackoffScale is the default back-off scaling factor DefaultConnectBackoffScale = 2 )
Variables ¶
This section is empty.
Functions ¶
func SetLogger ¶
func SetLogger(l LevelledLogger)
SetLogger enables logging for the library and wraps the supplied logger with a logPrefixer to denote locally generated logs
Types ¶
type Client ¶
Client is a TCP JSON-RPC client for Kodi.
Example ¶
package main import ( "github.com/pdf/kodirpc" ) func main() { kodirpc.NewClient(`127.0.0.1:9090`, kodirpc.NewConfig()) }
Output:
Example (Config) ¶
package main import ( "time" "github.com/pdf/kodirpc" ) func main() { config := kodirpc.NewConfig() config.ReadTimeout = 2 * time.Second kodirpc.NewClient(`127.0.0.1:9090`, config) }
Output:
Example (Logger) ¶
package main import ( "os" "github.com/Sirupsen/logrus" "github.com/pdf/kodirpc" ) func main() { // logrus is only used as an example, though loggers do need to satisfy the // LevelledLogger interface logger := &logrus.Logger{ Out: os.Stdout, Formatter: &logrus.TextFormatter{}, Hooks: make(logrus.LevelHooks), Level: logrus.WarnLevel, } kodirpc.SetLogger(logger) kodirpc.NewClient(`127.0.0.1:9090`, kodirpc.NewConfig()) }
Output:
func (*Client) Close ¶
Close the client connection, not further use of the Client is permitted after this method has been called.
func (*Client) Handle ¶
func (c *Client) Handle(method string, handler NotificationHandler)
Handle the notification method, using the specificed handler. The handler will be passed the data parameter from the incoming notification.
type Config ¶
type Config struct { // ReadTimeout is the time a call will wait for a response before failure. ReadTimeout time.Duration // ConnectTimeout is the time a re-/connection will be attempted before // failure. A value of zero attempts indefinitely. ConnectTimeout time.Duration // Reconnect determines whether the client will attempt to reconnect on // connection failure Reconnect bool // ConnectBackoffScale sets the scaling factor for back-off on failed // connection attempts ConnectBackoffScale int }
Config represents the user-configurable parameters for the client
type Error ¶
type Error struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
Error response.
type LevelledLogger ¶
type LevelledLogger interface { // Debugf handles debug level messages Debugf(format string, args ...interface{}) // Infof handles info level messages Infof(format string, args ...interface{}) // Warnf handles warn level messages Warnf(format string, args ...interface{}) // Errorf handles error level messages Errorf(format string, args ...interface{}) // Fatalf handles fatal level messages, and must exit the application Fatalf(format string, args ...interface{}) // Panicf handles debug level messages, and must panic the application Panicf(format string, args ...interface{}) }
LevelledLogger represents a minimal levelled logger
type NotificationHandler ¶
type NotificationHandler func(method string, data interface{})
NotificationHandler is a callback handler for notifications.