Skip to content
Snippets Groups Projects
Commit d35db8ca authored by Ivanov, Ivan (UG - Computer Science)'s avatar Ivanov, Ivan (UG - Computer Science)
Browse files

Merge branch 'initial' into 'master'

Initial POC

See merge request !1
parents 1d1d6070 f4e5c410
No related branches found
No related tags found
1 merge request!1Initial POC
[
{
"userid": "user1",
"url": "http://www.someamazingwebsite.com/1",
"type": "POST",
"timestamp": 1360662163000
},
{
"userid": "user2",
"url": "http://www.someamazingwebsite.com/2",
"type": "GET",
"timestamp": 1360662163000
},
{
"userid": "user2",
"url": "http://www.someamazingwebsite.com/1",
"type": "GET",
"timestamp": 1360662163000
},
{
"userid": "user2",
"url": "http://www.someamazingwebsite.com/1",
"type": "GET",
"timestamp": 1360462163000
},
{
"userid": "user2",
"url": "http://www.someamazingwebsite.com/3",
"type": "POST",
"timestamp": 1360462163000
}
]
\ No newline at end of file
go.mod 0 → 100644
module json-utility
go 1.16
require github.com/gorilla/mux v1.8.0
main.go 0 → 100644
/*
Example payload:
userid: A unique ID representing the user
url : The URL the visitor has accessed
type: The HTTP method used to access the URL
timestamp: The timestamp for when the action occurred
*/
package main
import (
"log"
"os"
"sync"
)
type Load struct {
Userid string `json:"userid"`
Url string `json:"url"`
TypeRequest string `json:"type"`
Timestamp int64 `json:"timestamp"`
}
type URLs struct {
URL map[string]*Dates
mux sync.RWMutex
}
type Dates struct {
Exists map[string]*Visits
}
type Visits struct {
mux sync.RWMutex
Counter int
UserIds map[string]bool
}
func main() {
//Check if the usage of the script has been correct.
if len(os.Args) != 2 {
log.Println("USAGE: ./json-utility [path/to/file]")
return
}
openFile(os.Args[1])
}
func openFile(argument string) {
jsonFile, err := os.Open(argument)
if err != nil {
log.Println(err)
return
}
log.Println("Successfully Opened", argument)
//Close when done.
defer jsonFile.Close()
result := handler(jsonFile)
for k, v := range result.URL {
log.Println("For URL: ", k)
for m, x := range v.Exists {
log.Println("↳", m, "there are:", x.Counter, "unique visits.")
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment