github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/setting/proxy.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package setting
     7  
     8  import (
     9  	"net/url"
    10  
    11  	"github.com/gitbundle/modules/log"
    12  )
    13  
    14  // Proxy settings
    15  var Proxy = struct {
    16  	Enabled       bool
    17  	ProxyURL      string
    18  	ProxyURLFixed *url.URL
    19  	ProxyHosts    []string
    20  }{
    21  	Enabled:    false,
    22  	ProxyURL:   "",
    23  	ProxyHosts: []string{},
    24  }
    25  
    26  func newProxyService() {
    27  	sec := Cfg.Section("proxy")
    28  	Proxy.Enabled = sec.Key("PROXY_ENABLED").MustBool(false)
    29  	Proxy.ProxyURL = sec.Key("PROXY_URL").MustString("")
    30  	if Proxy.ProxyURL != "" {
    31  		var err error
    32  		Proxy.ProxyURLFixed, err = url.Parse(Proxy.ProxyURL)
    33  		if err != nil {
    34  			log.Error("Global PROXY_URL is not valid")
    35  			Proxy.ProxyURL = ""
    36  		}
    37  	}
    38  	Proxy.ProxyHosts = sec.Key("PROXY_HOSTS").Strings(",")
    39  }