add: read config from subscription link for run command

This commit is contained in:
n3t1zen
2026-02-26 10:55:33 +08:00
parent 78e7f431d0
commit 54a8946274

View File

@@ -3,6 +3,7 @@ package main
import (
"context"
"io"
"net/http"
"os"
"os/signal"
"path/filepath"
@@ -49,8 +50,16 @@ func readConfigAt(path string) (*OptionsEntry, error) {
configContent []byte
err error
)
subscriptionLink := os.Getenv("SING_SUBSCRIPTION_LINK")
if path == "stdin" {
configContent, err = io.ReadAll(os.Stdin)
} else if path == "env" && subscriptionLink != "" {
configContentResponse, err := http.Get(subscriptionLink)
if err != nil {
return nil, E.Cause(err, "failed to GET subscription link")
}
defer configContentResponse.Body.Close()
configContent, err = io.ReadAll(configContentResponse.Body)
} else {
configContent, err = os.ReadFile(path)
}