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
f3cd7b0b
Commit
f3cd7b0b
authored
5 years ago
by
Hans Kristian Hoel
Browse files
Options
Downloads
Patches
Plain Diff
Implementet firebase read func and conneceted it with webhooks get
parent
b53eab04
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
assignment2/cmd/main.go
+1
-1
1 addition, 1 deletion
assignment2/cmd/main.go
assignment2/firebase.go
+5
-3
5 additions, 3 deletions
assignment2/firebase.go
assignment2/structs.go
+1
-1
1 addition, 1 deletion
assignment2/structs.go
assignment2/webhook.go
+2
-0
2 additions, 0 deletions
assignment2/webhook.go
with
9 additions
and
5 deletions
assignment2/cmd/main.go
+
1
−
1
View file @
f3cd7b0b
...
...
@@ -16,7 +16,7 @@ func main() {
assignment2
.
FBInit
()
//assignment2.FBSave()
assignment2
.
FBRead
()
//
assignment2.FBRead()
defer
assignment2
.
FBClose
()
port
:=
os
.
Getenv
(
"PORT"
)
...
...
This diff is collapsed.
Click to expand it.
assignment2/firebase.go
+
5
−
3
View file @
f3cd7b0b
...
...
@@ -42,18 +42,18 @@ func FBClose() {
func
FBSave
()
{
ref
:=
fb
.
Client
.
Collection
(
w
ebhook
.
Event
)
.
NewDoc
()
ref
:=
fb
.
Client
.
Collection
(
"W
ebhook
s"
)
.
NewDoc
()
webhook
.
ID
=
ref
.
ID
_
,
err
:=
ref
.
Set
(
fb
.
Ctx
,
webhook
)
if
err
!=
nil
{
fmt
.
Println
(
"ERROR saving
student
to Firestore DB: "
,
err
)
fmt
.
Println
(
"ERROR saving
webhook
to Firestore DB: "
,
err
)
//return errors.Wrap(err, "Error in FirebaseDatabase.Save()")
}
// return nil
}
func
FBRead
()
{
iter
:=
fb
.
Client
.
Collection
(
"
user
s"
)
.
Documents
(
fb
.
Ctx
)
iter
:=
fb
.
Client
.
Collection
(
"
Webhook
s"
)
.
Documents
(
fb
.
Ctx
)
for
{
doc
,
err
:=
iter
.
Next
()
if
err
==
iterator
.
Done
{
...
...
@@ -63,5 +63,7 @@ func FBRead() {
log
.
Fatalf
(
"Failed to iterate: %v"
,
err
)
}
fmt
.
Println
(
doc
.
Data
())
doc
.
DataTo
(
&
webhook
)
webhooks
=
append
(
webhooks
,
webhook
)
}
}
This diff is collapsed.
Click to expand it.
assignment2/structs.go
+
1
−
1
View file @
f3cd7b0b
...
...
@@ -56,7 +56,7 @@ type Status struct {
type
WebhookRegistration
struct
{
ID
string
`json:"id"`
Event
string
`json:"
E
vent"`
Event
string
`json:"
e
vent"`
URL
string
`json:"url"`
Time
time
.
Time
`json:"time"`
}
...
...
This diff is collapsed.
Click to expand it.
assignment2/webhook.go
+
2
−
0
View file @
f3cd7b0b
...
...
@@ -39,10 +39,12 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
fmt
.
Println
(
"Webhooks "
+
webhook
.
URL
+
" has been regstrerd"
)
case
http
.
MethodGet
:
FBRead
()
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
webhooks
)
if
err
!=
nil
{
http
.
Error
(
w
,
"Some thing went wrong"
+
err
.
Error
(),
http
.
StatusInternalServerError
)
}
//FBRead()
default
:
http
.
Error
(
w
,
"Method is invalid "
+
r
.
Method
,
http
.
StatusBadRequest
)
...
...
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