Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementaion of the Datetime client #1

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

MohamedFadel01
Copy link
Member

DateTime Client Implementation

This PR introduces a Go-based DateTime Client with the following features:

  • Fetches date/time from standard HTTP and Gin servers
  • Supports JSON and plain text responses
  • Implements retry mechanism and error handling
  • Includes Docker support and Makefile for easy development

Key Components:

  1. Client Implementation (client.go)

    • Core functionality to fetch datetime from servers
  2. Error Handling (errors.go)

    • Custom error types for various scenarios
  3. Main Application (main.go)

    • Demonstrates client usage
  4. Dockerfile

    • For containerization of the client
  5. Makefile

    • Automates build, test, and Docker operations
  6. README.md

    • Comprehensive documentation for the project

This PR sets up the complete DateTime Client project, ready for review and integration.

Comment on lines +3 to +9
on:
pull_request:
branches:
- main
push:
branches:
- main

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on push

- main

jobs:
golangci:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint

README.md Outdated
# DateTime Client

This project implements a client for fetching date and time information from two different server types: a standard HTTP server and a Gin server. The client supports both JSON and plain text responses.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the client should fetch date/time from any server exposing the api, not caring that the server is built with http or gin, no?

main.go Outdated
Comment on lines 12 to 20
serverURL := os.Getenv("SERVER_URL")
serverPort := os.Getenv("SERVER_PORT")
serverPortGin := os.Getenv("SERVER_PORT_GIN")

if serverURL == "" || serverPort == "" || serverPortGin == "" {
log.Fatal("SERVER_URL, SERVER_PORT, and SERVER_PORT_GIN must be set")
}

client.SetupEnv(serverURL, serverPort, serverPortGin)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not using flags with default values

main.go Outdated
Comment on lines 13 to 14
serverPort := os.Getenv("SERVER_PORT")
serverPortGin := os.Getenv("SERVER_PORT_GIN")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be done, the client should fetch data from whatever server, so no need to force the server to fetch data from both servers every time

main.go Outdated
serverTypes := []string{"standard", "gin"}
contentTypes := []string{"application/json", "text/plain"}

for _, serverType := range serverTypes {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the client can take an argument representing the response type, and then you can use it to fetch the date and time with the required format so your client can be more generic

main.go Outdated
log.Fatal("SERVER_URL, SERVER_PORT, and SERVER_PORT_GIN must be set")
}

client.SetupEnv(serverURL, serverPort, serverPortGin)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should you set env here? the variables should be already set at this point

client/client.go Outdated
//
// The function uses an exponential backoff retry mechanism for failed requests.
func GetDateTime(serverType, contentType string) (string, error) {
serverURL := os.Getenv("SERVER_URL")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there can be a client holding the needed values needed to get the data instead of fetching them over and over again

…tion and Updating Makefile, Docker, and Documentation accordingly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Datetime-Client-Mohamed Fadel
2 participants