golift.io/starr@v1.0.0/starrcmd/example_test.go (about) 1 //nolint:exhaustive,testableexamples 2 package starrcmd_test 3 4 import ( 5 "fmt" 6 7 "golift.io/starr" 8 "golift.io/starr/starrcmd" 9 ) 10 11 /* This example assumes you want to handle custom script command hooks for all applications. 12 Trim it to what you need; this is just an example. 13 */ 14 15 // This is an example main() function that uses the golft.io/starr/starrcmd module. 16 func Example() { 17 // Do your own configuration input here. 18 cmd, err := starrcmd.New() 19 if err != nil { 20 panic(err) 21 } 22 23 switch cmd.App { 24 case starr.Radarr: 25 DoRadarr(cmd) 26 case starr.Sonarr: 27 DoSonarr(cmd) 28 case starr.Readarr: 29 DoReadarr(cmd) 30 case starr.Lidarr: 31 DoLidarr(cmd) 32 case starr.Prowlarr: 33 DoProwlarr(cmd) 34 } 35 } 36 37 // DoRadarr handles any Radarr event. 38 func DoRadarr(cmd *starrcmd.CmdEvent) { //nolint:cyclop 39 fmt.Println("Processing Radarr Event: ", cmd.Type) 40 41 switch cmd.Type { 42 case starrcmd.EventGrab: 43 grab, err := cmd.GetRadarrGrab() 44 if err != nil { 45 panic(err) 46 } 47 48 fmt.Println(grab.Title) 49 case starrcmd.EventApplicationUpdate: 50 update, err := cmd.GetRadarrApplicationUpdate() 51 if err != nil { 52 panic(err) 53 } 54 55 fmt.Println(update.Message) 56 case starrcmd.EventDownload: 57 download, err := cmd.GetRadarrDownload() 58 if err != nil { 59 panic(err) 60 } 61 62 fmt.Println(download.Title) 63 case starrcmd.EventHealthIssue: 64 health, err := cmd.GetRadarrHealthIssue() 65 if err != nil { 66 panic(err) 67 } 68 69 fmt.Println(health.IssueType, health.Message) 70 case starrcmd.EventMovieFileDelete: 71 movie, err := cmd.GetRadarrMovieFileDelete() 72 if err != nil { 73 panic(err) 74 } 75 76 fmt.Println(movie.Title, movie.Path) 77 case starrcmd.EventTest: 78 // nothing, it's useless 79 default: 80 fmt.Println("Ignored Radarr Event: ", cmd.Type) 81 } 82 } 83 84 /* The following procedures are just more examples. They're left empty on purpose. */ 85 86 // DoSonarr handles any Sonarr event. 87 func DoSonarr(command *starrcmd.CmdEvent) { 88 fmt.Println("Processing Sonarr Event: ", command.Type) 89 90 switch command.Type { 91 case starrcmd.EventGrab: 92 case starrcmd.EventApplicationUpdate: 93 case starrcmd.EventDownload: 94 case starrcmd.EventHealthIssue: 95 default: 96 fmt.Println("Ignored Sonarr Event: ", command.Type) 97 } 98 } 99 100 // DoLidarr handles any Lidarr event. 101 func DoLidarr(command *starrcmd.CmdEvent) { 102 fmt.Println("Processing Lidarr Event: ", command.Type) 103 104 switch command.Type { 105 case starrcmd.EventGrab: 106 case starrcmd.EventApplicationUpdate: 107 case starrcmd.EventDownload: 108 case starrcmd.EventHealthIssue: 109 default: 110 fmt.Println("Ignored Lidarr Event: ", command.Type) 111 } 112 } 113 114 // DoReadarr handles any Readarr event. 115 func DoReadarr(command *starrcmd.CmdEvent) { 116 fmt.Println("Processing Readarr Event: ", command.Type) 117 118 switch command.Type { 119 case starrcmd.EventGrab: 120 case starrcmd.EventApplicationUpdate: 121 case starrcmd.EventDownload: 122 case starrcmd.EventHealthIssue: 123 default: 124 fmt.Println("Ignored Readarr Event: ", command.Type) 125 } 126 } 127 128 // DoProwlarr handles any Prowlarr event. 129 func DoProwlarr(command *starrcmd.CmdEvent) { 130 fmt.Println("Processing Prowlarr Event: ", command.Type) 131 132 switch command.Type { 133 case starrcmd.EventApplicationUpdate: 134 case starrcmd.EventHealthIssue: 135 default: 136 fmt.Println("Ignored Prowlarr Event: ", command.Type) 137 } 138 }