Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cloud - Assignment 2
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hans Kristian Hoel
Cloud - Assignment 2
Commits
bd5242a5
Commit
bd5242a5
authored
5 years ago
by
Hans Kristian Hoel
Browse files
Options
Downloads
Patches
Plain Diff
did some commenting
parent
65e231b3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
assignment2/firebase.go
+6
-6
6 additions, 6 deletions
assignment2/firebase.go
assignment2/webhook.go
+9
-10
9 additions, 10 deletions
assignment2/webhook.go
with
15 additions
and
16 deletions
assignment2/firebase.go
+
6
−
6
View file @
bd5242a5
...
...
@@ -63,15 +63,15 @@ func FBRead() {
log
.
Fatalf
(
"Failed to iterate: %v"
,
err
)
}
fmt
.
Println
(
doc
.
Data
())
doc
.
DataTo
(
&
webhook
)
tempCount
:=
0
for
i
:=
range
webhooks
{
if
webhooks
[
i
]
.
ID
==
webhook
.
ID
{
tempCount
++
doc
.
DataTo
(
&
webhook
)
// sets data in to webhook struct
tempCount
:=
0
// controll for duplicate
for
i
:=
range
webhooks
{
// lopps true webhooks
if
webhooks
[
i
]
.
ID
==
webhook
.
ID
{
// cheek it the webhook allready exist
tempCount
++
//adds 1
}
}
if
tempCount
==
0
{
if
tempCount
==
0
{
// if tempCount is 0 it means that there is no duplicats and can add webhook
webhooks
=
append
(
webhooks
,
webhook
)
}
...
...
This diff is collapsed.
Click to expand it.
assignment2/webhook.go
+
9
−
10
View file @
bd5242a5
...
...
@@ -25,16 +25,15 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
switch
r
.
Method
{
case
http
.
MethodPost
:
err
:=
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
webhook
)
err
:=
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
webhook
)
//decode to webhook
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
}
webhook
.
Time
=
time
.
Now
()
IDNum
++
webhook
.
Time
=
time
.
Now
()
// sets time stamp
FBSave
()
webhooks
=
append
(
webhooks
,
webhook
)
FBSave
()
// saves webhook to firebase
webhooks
=
append
(
webhooks
,
webhook
)
// saves webhook to webhooks
fmt
.
Fprintln
(
w
,
len
(
webhooks
)
-
1
)
fmt
.
Println
(
"Webhooks "
+
webhook
.
URL
+
" has been regstrerd"
)
...
...
@@ -44,19 +43,19 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
http
.
Header
.
Add
(
w
.
Header
(),
"Content-Type"
,
"application/json"
)
// makes the print look good
parts
:=
strings
.
Split
(
r
.
URL
.
Path
,
"/"
)
//finds url parts
fmt
.
Println
(
parts
)
if
len
(
parts
)
==
5
{
if
len
(
parts
)
==
5
{
// this need to be fixed
tempInt
,
err
:=
strconv
.
Atoi
(
parts
[
4
])
tempInt
,
err
:=
strconv
.
Atoi
(
parts
[
4
])
// gets the numid of choosen webhook
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
}
err
=
json
.
NewEncoder
(
w
)
.
Encode
(
webhooks
[
tempInt
-
1
])
err
=
json
.
NewEncoder
(
w
)
.
Encode
(
webhooks
[
tempInt
])
// encode choosen webhook
if
err
!=
nil
{
http
.
Error
(
w
,
"Some thing went wrong"
+
err
.
Error
(),
http
.
StatusInternalServerError
)
}
}
else
{
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
webhooks
)
}
else
{
// if not choosen any webhooks
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
webhooks
)
// encode all webhooks
if
err
!=
nil
{
http
.
Error
(
w
,
"Some thing went wrong"
+
err
.
Error
(),
http
.
StatusInternalServerError
)
}
...
...
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