-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
82 lines (59 loc) · 1.67 KB
/
main.go
File metadata and controls
82 lines (59 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"encoding/json"
"net/http"
"time"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
type Response struct{
Slack_name string `json:"slack_name"`
Current_day string `json:"current_day"`
Utc_time string `json:"utc_time"`
Track string `json:"track"`
Github_file_url string `json:"github_file_url"`
Github_repo_url string `json:"github_repo_url"`
Status_code int `json:"status_code"`
}
func currentDay()(string){
currentTime := time.Now()
current_day := currentTime.Weekday()
day_of_the_week := current_day.String()
return day_of_the_week
}
func vaildUtcTime()(string){
currentTime := time.Now().UTC()
window := 2 * time.Minute
lowMark := currentTime.Add(-window)
upMark := currentTime.Add(window)
if (currentTime.After(lowMark) && currentTime.Before(upMark)){
formattedTime := currentTime.Format("2006-01-02T15:04:05Z")
return formattedTime
}else{
return ""
}
}
func main() {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Get("/api", func(w http.ResponseWriter, r *http.Request) {
slack_name := r.URL.Query().Get("slack_name")
track := r.URL.Query().Get("track")
data := Response{
Slack_name: slack_name,
Current_day: currentDay(),
Utc_time: vaildUtcTime(),
Track: track,
Github_file_url: "https://github.com/Mac-5/Hng_FirstTask/blob/main/main.go",
Github_repo_url: "https://github.com/Mac-5/Hng_FirstTask",
Status_code: http.StatusOK,
}
json, err := json.Marshal(data)
if err != nil{
http.Error(w, err.Error(), http.StatusInternalServerError)
}
w.Header().Set("Content-Type","application/json")
w.Write(json)
})
http.ListenAndServe(":3000", r)
}