Categorygithub.com/acamilleri/go-plexhooks
modulepackage
0.1.0
Repository: https://github.com/acamilleri/go-plexhooks.git
Documentation: pkg.go.dev

# README

Plex Hooks

Go Report Card

Library to listen Plex Webhook Events and execute actions.

Plex Webhooks require a Plex Pass subscription

Installation

Use the library in your own app to register your actions.

go get github.com/acamilleri/go-plexhooks

Usage

You can check a real world example with myplexhooks repository.

Example:

package main

import (
    "net"

    "github.com/sirupsen/logrus"
    "github.com/acamilleri/go-plexhooks"
    "github.com/acamilleri/go-plexhooks/plex"
)

type MyActionOnMediaPlay struct{}

func (a *MyActionOnMediaPlay) Name() string {
	return "MyActionOnMediaPlay"
}

func (a *MyActionOnMediaPlay) Execute(event plex.Event) error {
	fmt.Printf("I'm print a message when i received a MediaPlay event")
	return nil
}

func main() {
	listenAddr, err := net.ResolveTCPAddr("tcp4", "127.0.0.1:8080")
	if err != nil {
		panic(err)
	}

	actions := plexhooks.NewActions()
	actions.Add(plex.MediaPlay, &MyActionOnMediaPlay{})

	app := plexhooks.New(plexhooks.Definition{
		ListenAddr: listenAddr,
		Actions:    actions,
		Logger: plexhooks.LoggerDefinition{
			Level:     logrus.InfoLevel,
			Formatter: &logrus.JSONFormatter{},
		},
	})
    
    err := app.Run()
    if err != nil {
        panic(err)
    }
}

Metrics

The Run function running a metrics handler to have some metrics about the events handler and actions executed.

Metrics are expose at /metrics path in Prometheus format.

You can find all metrics available here

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

# Packages

No description provided by the author

# Functions

New create app from Definition values.
NewActions return an initialize map to define actions to run on each event.

# Structs

App struct with listenAddr and actions.
Definition app configuration.
LoggerDefinition logger configuration.

# Interfaces

Action generic interface to create action.

# Type aliases

Actions list of Action by Event name.