88 "fmt"
99 "io"
1010 "net/http"
11+ "os"
1112 "os/exec"
1213
1314 "github.com/go-faster/errors"
@@ -30,12 +31,22 @@ type Server struct {
3031 trace trace.Tracer
3132}
3233
34+ func (s Server ) getEnvDefault (key , def string ) string {
35+ v := os .Getenv (key )
36+ if v == "" {
37+ return def
38+ }
39+ return v
40+ }
41+
3342func (s Server ) makeExternalRequest (ctx context.Context ) error {
3443 // Make external request.
3544 ctx , span := s .trace .Start (ctx , "Server.makeExternalRequest" )
3645 defer span .End ()
3746
38- req , err := http .NewRequestWithContext (ctx , "GET" , "https://www.google.com/" , http .NoBody )
47+ uri := s .getEnvDefault ("EXTERNAL_URL" , "https://www.google.com/" )
48+
49+ req , err := http .NewRequestWithContext (ctx , "GET" , uri , http .NoBody )
3950 if err != nil {
4051 return errors .Wrap (err , "create external request" )
4152 }
@@ -73,9 +84,11 @@ func (s Server) makeCurlRequest(ctx context.Context) error {
7384 ctx , span := s .trace .Start (ctx , "Server.makeCurlRequest" )
7485 defer span .End ()
7586
87+ uri := s .getEnvDefault ("CURL_URL" , "https://ifconfig.me" )
88+
7689 bufErr := new (bytes.Buffer )
7790 buf := new (bytes.Buffer )
78- cmd := exec .CommandContext (ctx , "curl" , "-s" , "https://ifconfig.me" , "-o" , "-" , "--max-time" , "5" )
91+ cmd := exec .CommandContext (ctx , "curl" , "-s" , uri , "-o" , "-" , "--max-time" , "5" )
7992 cmd .Stdout = buf
8093 cmd .Stderr = bufErr
8194
0 commit comments