Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openfaas-faas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Team Jaz CS 598 CCC Final Project
openfaas-faas
Commits
26c86718
Commit
26c86718
authored
7 years ago
by
Burton Rheutan
Committed by
Alex Ellis
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
updated hubstats to accept repo for pull count
Signed-off-by:
Burton Rheutan
<
rheutan7@gmail.com
>
parent
d1fb0084
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sample-functions/DockerHubStats/main.go
+31
-11
31 additions, 11 deletions
sample-functions/DockerHubStats/main.go
with
31 additions
and
11 deletions
sample-functions/DockerHubStats/main.go
+
31
−
11
View file @
26c86718
...
...
@@ -10,18 +10,22 @@ import (
"strings"
)
type
dockerHubStatsType
struct
{
type
dockerHub
Org
StatsType
struct
{
Count
int
`json:"count"`
}
type
dockerHubRepoStatsType
struct
{
PullCount
int
`json:"pull_count"`
}
func
sanitizeInput
(
input
string
)
string
{
parts
:=
strings
.
Split
(
input
,
"
\n
"
)
return
strings
.
Trim
(
parts
[
0
],
" "
)
}
func
request
Hub
Stats
(
org
string
)
dockerHubStatsTyp
e
{
func
requestStats
(
repo
string
)
[]
byt
e
{
client
:=
http
.
Client
{}
res
,
err
:=
client
.
Get
(
"https://hub.docker.com/v2/repositories/"
+
org
)
res
,
err
:=
client
.
Get
(
"https://hub.docker.com/v2/repositories/"
+
repo
)
if
err
!=
nil
{
log
.
Fatalln
(
"Unable to reach Docker Hub server."
)
}
...
...
@@ -31,9 +35,19 @@ func requestHubStats(org string) dockerHubStatsType {
log
.
Fatalln
(
"Unable to parse response from server."
)
}
dockerHubStats
:=
dockerHubStatsType
{}
json
.
Unmarshal
(
body
,
&
dockerHubStats
)
return
dockerHubStats
return
body
}
func
parseOrgStats
(
response
[]
byte
)
dockerHubOrgStatsType
{
dockerHubOrgStats
:=
dockerHubOrgStatsType
{}
json
.
Unmarshal
(
response
,
&
dockerHubOrgStats
)
return
dockerHubOrgStats
}
func
parseRepoStats
(
response
[]
byte
)
dockerHubRepoStatsType
{
dockerHubRepoStats
:=
dockerHubRepoStatsType
{}
json
.
Unmarshal
(
response
,
&
dockerHubRepoStats
)
return
dockerHubRepoStats
}
func
main
()
{
...
...
@@ -41,13 +55,19 @@ func main() {
if
err
!=
nil
{
log
.
Fatal
(
"Unable to read standard input:"
,
err
)
}
org
:=
string
(
input
)
request
:=
string
(
input
)
if
len
(
input
)
==
0
{
log
.
Fatalln
(
"A username
or
organisation is required."
)
log
.
Fatalln
(
"A username
/
organisation
or repository
is required."
)
}
org
=
sanitizeInput
(
org
)
dockerHubStats
:=
request
Hub
Stats
(
org
)
request
=
sanitizeInput
(
request
)
response
:=
requestStats
(
request
)
fmt
.
Printf
(
"The organisation or user %s has %d repositories on the Docker hub.
\n
"
,
org
,
dockerHubStats
.
Count
)
if
strings
.
Contains
(
request
,
"/"
)
{
dockerHubRepoStats
:=
parseRepoStats
(
response
)
fmt
.
Printf
(
"Repo: %s has been pulled %d times from the Docker Hub"
,
request
,
dockerHubRepoStats
.
PullCount
)
}
else
{
dockerHubOrgStats
:=
parseOrgStats
(
response
)
fmt
.
Printf
(
"The organisation or user %s has %d repositories on the Docker hub.
\n
"
,
request
,
dockerHubOrgStats
.
Count
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment