Skip to content

Commit

Permalink
style: add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Michsior14 committed Nov 26, 2023
1 parent c351bb4 commit 48c0cd5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ type GluetunResponse struct {
}

var (
// Transmission
transmissionHostname = flag.String("transmission-hostname", "127.0.0.1", "transmission hostname")
transmissionPort = flag.Int("transmission-port", 9091, "transmission port")
transmissionUsername = os.Getenv("TRANSMISSION_USERNAME")
transmissionPassword = os.Getenv("TRANSMISSION_PASSWORD")

// Gluetun
gluetunHostname = getEnv("GLUETUN_HOSTNAME", "127.0.0.1")
gluetunPort = getEnv("GLUETUN_PORT", "8000")

// Control flow
initialDelayStr = getEnv("INITIAL_DELAY", "5s")
checkIntervalStr = getEnv("CHECK_INTERVAL", "1m")
errorIntervalStr = getEnv("ERROR_INTERVAL", "5s")
Expand All @@ -47,10 +50,10 @@ func main() {
time.Sleep(initialDelay)

httpClient := resty.New()

transmissionClient, err := transmissionrpc.New(*transmissionHostname, transmissionUsername, transmissionPassword, &transmissionrpc.AdvancedConfig{
Port: uint16(*transmissionPort),
})

if err != nil {
log.Fatalf("failed to create transmission client: %v", err)
}
Expand All @@ -76,6 +79,7 @@ func main() {
err = transmissionClient.SessionArgumentsSet(context.Background(), transmissionrpc.SessionArguments{
PeerPort: &transmissionPeerPort,
})

if err != nil {
log.Printf("failed to set transmission peer port: %v", err)
} else {
Expand All @@ -94,6 +98,9 @@ func main() {
}
}

/**
* Return fallback fallback if environment variable is not set or empty
*/
func getEnv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
Expand Down

0 comments on commit 48c0cd5

Please sign in to comment.