Make the external url of cache server configurable if necessary
Some checks failed
checks / check and test (push) Failing after 21s

This commit is contained in:
林玮 (Jade Lin)
2024-06-17 23:26:04 +08:00
committed by Matthias Kesler
parent 6a090f67e5
commit 9661a37003
3 changed files with 15 additions and 7 deletions

View File

@@ -38,10 +38,11 @@ type Handler struct {
gcing atomic.Bool
gcAt time.Time
outboundIP string
outboundIP string
advertiseURL string
}
func StartHandler(dir, outboundIP string, port uint16, logger logrus.FieldLogger) (*Handler, error) {
func StartHandler(dir, advertiseURL, outboundIP string, port uint16, logger logrus.FieldLogger) (*Handler, error) {
h := &Handler{}
if logger == nil {
@@ -71,6 +72,8 @@ func StartHandler(dir, outboundIP string, port uint16, logger logrus.FieldLogger
}
h.storage = storage
h.advertiseURL = advertiseURL
if outboundIP != "" {
h.outboundIP = outboundIP
} else if ip := common.GetOutboundIP(); ip == nil {
@@ -111,10 +114,13 @@ func StartHandler(dir, outboundIP string, port uint16, logger logrus.FieldLogger
}
func (h *Handler) ExternalURL() string {
// TODO: make the external url configurable if necessary
return fmt.Sprintf("http://%s:%d",
h.outboundIP,
h.listener.Addr().(*net.TCPAddr).Port)
if h.advertiseURL != "" {
return h.advertiseURL
} else {
return fmt.Sprintf("http://%s:%d",
h.outboundIP,
h.listener.Addr().(*net.TCPAddr).Port)
}
}
func (h *Handler) Close() error {