Count duplicate items in slice/array?

Hi all,

I have data input like this:

[
{
“id”: 1,
“host”: “abc. com”,
“remote_addr”: “14.161.36.28”,
“request_method”: “GET”,
“request_uri”: “/test.txt”,
},
{
“id”: 2,
“host”: “abc. com”,
“remote_addr”: “14.161.36.28”,
“request_method”: “GET”,
“request_uri”: “/”,
},
{
“id”: 3,
“host”: “abc. com”,
“remote_addr”: “14.161.36.28”,
“request_method”: “GET”,
“request_uri”: “/test.txt”,
},
{
“id”: 4,
“host”: “abc. com”,
“remote_addr”: “14.161.36.29”,
“request_method”: “GET”,
“request_uri”: “/”,
},
{
“id”: 5,
“host”: “abc. com”,
“remote_addr”: “14.161.36.29”,
“request_method”: “GET”,
“request_uri”: “/”,
},
]

but I want to count and output to like this:

{
“static_file”: “/test.txt”,
“static_file_hits”: 2,
“staticfile_visitor”: 2,
},
{
“static_file”: “/”,
“static_file_hits”: 3,
“staticfile_visitor”: 2,
},

static_file = request_uri
static_file_hits = number call to request_uri
staticfile_visitor= number remote_addr call to request_uri

Could you pls help me count and maping data?
Many thanks

Have you tried anything? Does it work?

I have try do some code like that but not work

How is this link related to analysing a JSON object?

Take a look at the example for JSON is decoded in Go: https://golang.org/pkg/encoding/json/#example_Unmarshal

Then Think about your logic:

  • How do you recognize a static file?
  • How do you recognize a visitor?
1 Like

Thanks You, I have resolved the issue!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.