Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Assignment2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kenneth Tran
Assignment2
Commits
51df4c0a
Commit
51df4c0a
authored
Oct 27, 2019
by
Kenneth Tran
Browse files
Options
Downloads
Patches
Plain Diff
Setup handler and structs demo
parent
35683fe7
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
main.go
+22
-0
22 additions, 0 deletions
main.go
packs/commits.go
+79
-0
79 additions, 0 deletions
packs/commits.go
packs/issues.go
+0
-0
0 additions, 0 deletions
packs/issues.go
packs/languages.go
+9
-0
9 additions, 0 deletions
packs/languages.go
with
110 additions
and
0 deletions
main.go
+
22
−
0
View file @
51df4c0a
package
main
import
(
"net/http"
A
"oblig2/packs"
// C "oblig2/packs"
"log"
"os"
)
func
main
(){
port
:=
os
.
Getenv
(
"PORT"
)
port
=
"8080"
if
port
==
""
{
log
.
Fatal
(
"PORT must be set"
)
}
A
.
GetCommits
()
log
.
Fatal
(
http
.
ListenAndServe
(
":"
+
port
,
nil
))
// B.GetIssues()
// C.GetLanguages()
}
This diff is collapsed.
Click to expand it.
packs/commits.go
+
79
−
0
View file @
51df4c0a
package
packs
import
(
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"strconv"
)
const
URL
=
"https://gitlab.example.com/api/v4/projects"
type
Repo1
struct
{
//struct repo with most commits
Id
int
`json: "id"`
MostCommits
string
`json:"path_with_namespace"`
Counter1
nt
//convert to Jsonformat
}
type
Repo2
struct
{
// struct repo with second most commits
SecondCommits
string
`json:"path_with_namespace"`
Counter2
int
//convert to Jsonformat
}
type
MergeRep
struct
{
Repo1
Repo1
Repo2
Repo2
}
func
GetCommits
(){
// Caps on G to call from main, syntax on mac
http
.
HandleFunc
(
"/repocheck/v1/commits"
,
handlerCommits
)
}
func
countMost
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
pointer
*
[]
repo1
){
for
j
:=
0
;
j
<=
len
(
*
pointer
);
j
++
{
spesificPro
:=
strconv
.
Itoa
(
*
pointer
[
j
]
.
Id
)
url
:=
URL
+
spesificPro
+
"/repository/commits"
reponse
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
//error handler
fmt
.
Println
(
"Error: we have a problem"
,
err
)
}
}
}
func
handlerCommits
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
response
,
err
:=
http
.
Get
(
URL
)
if
err
!=
nil
{
//error handler
fmt
.
Println
(
"Error: we have a problem"
,
err
)
}
if
err2
!=
nil
{
//error handler
fmt
.
Println
(
"Error: we have a problem"
,
err2
)
}
var
content
Repo1
var
content2
Repo2
var
merged
MergeRep
err
=
json
.
NewDecoder
(
response
.
Body
)
.
Decode
(
&
content
)
err2
=
json
.
NewDecoder
(
response2
.
Body
)
.
Decode
(
&
content2
)
merged
.
Repo1
=
content
merged
.
Repo2
=
content2
var
buffer
=
new
(
bytes
.
Buffer
)
encode
:=
json
.
NewEncoder
(
buffer
)
encode
.
Encode
(
merged
)
w
.
Header
()
.
Set
(
"Content-type"
,
"application/json"
)
io
.
Copy
(
w
,
buffer
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
packs/issues.go
deleted
100644 → 0
+
0
−
0
View file @
35683fe7
This diff is collapsed.
Click to expand it.
packs/languages.go
+
9
−
0
View file @
51df4c0a
//package packs
//func getLanguages(){
// http.HandleFunc("/x/x/x/", handlercommits)
//func handlerCommits(w http.ResponseWriter, r *http.Request) {
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