Skip to content

Commit

Permalink
fix: fix server an port configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
eyad-hussein committed Jul 8, 2024
1 parent e9de1a8 commit 616bcca
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,32 @@ type Client interface {
}

type RealClient struct {
host string
port string
client *http.Client
baseUrl string
port string
client *http.Client
}

func NewRealClient(host, port string, timeout time.Duration) *RealClient {
func NewRealClient(baseUrl, port string, timeout time.Duration) *RealClient {
if baseUrl == "" {
baseUrl = os.Getenv("SERVER_URL")
}
if port == "" {
port = os.Getenv("PORT")
}

port = ":" + port

return &RealClient{
host: host,
port: port,
baseUrl: baseUrl,
port: port,
client: &http.Client{
Timeout: timeout,
},
}
}

func (c *RealClient) GetCurrentDateTime() ([]byte, error) {
var host = c.host
var port = ":" + c.port

if serverUrlEnv := os.Getenv("SERVER_URL"); serverUrlEnv != "" {
host = serverUrlEnv
}
if portEnv := os.Getenv("PORT"); portEnv != "" {
port = ":" + portEnv
}

url := host + port

req, err := http.NewRequest(http.MethodGet, url+"/datetime", nil)
req, err := http.NewRequest(http.MethodGet, c.baseUrl+c.port+"/datetime", nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 616bcca

Please sign in to comment.