When forwarding a request, every time the application writes to the database some information about the request. The table ShortcutLog is used for this functionality.
This table has the following structure:
ShortcutID INT,
IPAddress VARCHAR(39),
UserAgent VARCHAR(100),
Region VARCHAR(40),
AccessedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
ResponseTime INT(6),
Your task is to provide analytics queries and JSON-based endpoints to have a better understanding of how your shortened link is used.
Routes to endpoints are defined here:
|
api := router.PathPrefix("/api").Subrouter() |
|
api.Use(Authentication) |
|
|
|
// shortcut routes |
|
api.HandleFunc("/shortcuts", createShortcut).Methods("POST") |
|
api.HandleFunc("/shortcuts", listShortcuts).Methods("GET") |
|
api.HandleFunc("/shortcuts/{id}", getShortcut).Methods("GET") |
|
api.HandleFunc("/shortcuts/{id}", updateShortcut).Methods("PUT") |
|
api.HandleFunc("/shortcuts/{id}", deleteShortcut).Methods("DELETE") |
They get authenticated using this middleware:
|
func Authentication(next http.Handler) http.Handler { |
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
header := r.Header.Get("Authorization") |
|
headerParts := strings.Split(header, "Bearer ") |
|
if len(headerParts) < 2 { |
|
responseMalformedJWT.JSON(w) |
|
return |
|
} |
|
|
|
u, err := models.UserJWT(headerParts[1]) |
|
if err != nil { |
|
log.Println(err) |
|
responseUnauthorized.JSON(w) |
|
return |
|
} |
|
|
|
ctx := context.WithValue(r.Context(), "User", u) |
|
next.ServeHTTP(w, r.WithContext(ctx)) |
|
}) |
|
} |
If you have any questions about it feel free to ask.
Regards,
David
When forwarding a request, every time the application writes to the database some information about the request. The table
ShortcutLogis used for this functionality.This table has the following structure:
Your task is to provide analytics queries and JSON-based endpoints to have a better understanding of how your shortened link is used.
Routes to endpoints are defined here:
shortcut/routes/router.go
Lines 15 to 23 in acf743a
They get authenticated using this middleware:
shortcut/routes/middlewares.go
Lines 55 to 74 in acf743a
If you have any questions about it feel free to ask.
Regards,
David