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

Analytics Queries and Endpoints #1

Open
davidkroell opened this issue Sep 25, 2020 · 2 comments
Open

Analytics Queries and Endpoints #1

davidkroell opened this issue Sep 25, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed

Comments

@davidkroell
Copy link
Owner

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

@davidkroell davidkroell added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers hacktoberfest labels Sep 25, 2020
@dannylwe
Copy link

Hi, I want to work on this for hacktoberfest.

@davidkroell
Copy link
Owner Author

Hi, @dannylwe
Thanks for your support. I've assigned this issue to you.

@davidkroell davidkroell pinned this issue Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants