MCPcopy
hub / github.com/EverythingSuckz/TG-FileStreamBot / setupEnvVars

Method setupEnvVars

config/config.go:167–199  ·  view source on GitHub ↗
(log *zap.Logger, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

165}
166
167func (c *config) setupEnvVars(log *zap.Logger, cmd *cobra.Command) {
168 c.loadFromEnvFile(log)
169 c.loadConfigFromArgs(log, cmd)
170 err := envconfig.Process("", c)
171 if err != nil {
172 log.Fatal("Error while parsing env variables", zap.Error(err))
173 }
174 var ipBlocked bool
175 ip, err := getIP(c.UsePublicIP)
176 if err != nil {
177 log.Error("Error while getting IP", zap.Error(err))
178 ipBlocked = true
179 }
180 if c.Host == "" {
181 c.Host = "http://" + ip + ":" + strconv.Itoa(c.Port)
182 if c.UsePublicIP {
183 if ipBlocked {
184 log.Sugar().Warn("Can't get public IP, using local IP")
185 } else {
186 log.Sugar().Warn("You are using a public IP, please be aware of the security risks while exposing your IP to the internet.")
187 log.Sugar().Warn("Use 'HOST' variable to set a domain name")
188 }
189 }
190 log.Sugar().Info("HOST not set, automatically set to " + c.Host)
191 }
192 val := reflect.ValueOf(c).Elem()
193 for _, env := range os.Environ() {
194 if strings.HasPrefix(env, "MULTI_TOKEN") {
195 c.MultiTokens = append(c.MultiTokens, botTokenRegex.FindStringSubmatch(env)[1])
196 }
197 }
198 val.FieldByName("MultiTokens").Set(reflect.ValueOf(c.MultiTokens))
199}
200
201func Load(log *zap.Logger, cmd *cobra.Command) {
202 log = log.Named("Config")

Callers 1

LoadFunction · 0.80

Calls 4

loadFromEnvFileMethod · 0.95
loadConfigFromArgsMethod · 0.95
getIPFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected