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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hans Kristian Hoel
Cloud - Assignment 2
Commits
a6d48ffe
Commit
a6d48ffe
authored
5 years ago
by
Hans Kristian Hoel
Browse files
Options
Downloads
Patches
Plain Diff
i have implementet delete func to firebase
parent
bd5242a5
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
assignment2/cmd/main.go
+1
-0
1 addition, 0 deletions
assignment2/cmd/main.go
assignment2/firebase.go
+22
-0
22 additions, 0 deletions
assignment2/firebase.go
assignment2/webhook.go
+12
-0
12 additions, 0 deletions
assignment2/webhook.go
with
35 additions
and
0 deletions
assignment2/cmd/main.go
+
1
−
0
View file @
a6d48ffe
...
@@ -17,6 +17,7 @@ func main() {
...
@@ -17,6 +17,7 @@ func main() {
assignment2
.
FBInit
()
assignment2
.
FBInit
()
//assignment2.FBSave()
//assignment2.FBSave()
//assignment2.FBRead()
//assignment2.FBRead()
//assignment2.FBDelete()
defer
assignment2
.
FBClose
()
defer
assignment2
.
FBClose
()
port
:=
os
.
Getenv
(
"PORT"
)
port
:=
os
.
Getenv
(
"PORT"
)
...
...
This diff is collapsed.
Click to expand it.
assignment2/firebase.go
+
22
−
0
View file @
a6d48ffe
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"fmt"
"fmt"
"log"
"log"
"github.com/pkg/errors"
"golang.org/x/net/context"
"golang.org/x/net/context"
firebase
"firebase.google.com/go"
// Same as python's import dependency as alias.
firebase
"firebase.google.com/go"
// Same as python's import dependency as alias.
...
@@ -77,3 +78,24 @@ func FBRead() {
...
@@ -77,3 +78,24 @@ func FBRead() {
}
}
}
}
func
FBDelete
(
ID
string
)
error
{
docRef
:=
fb
.
Client
.
Collection
(
"Webhooks"
)
.
Doc
(
ID
)
_
,
err
:=
docRef
.
Delete
(
fb
.
Ctx
)
if
err
!=
nil
{
fmt
.
Printf
(
"ERROR deleting student (%v) from Firestore DB: %v
\n
"
,
err
)
return
errors
.
Wrap
(
err
,
"Error in FirebaseDatabase.Delete()"
)
}
return
nil
}
// Delete deletes a students from the DB.
// func (db *FirestoreDatabase) Delete(s *Student) error {
// docRef := db.Client.Collection(db.CollectionName).Doc(s.ID)
// _, err := docRef.Delete(db.Ctx)
// if err != nil {
// fmt.Printf("ERROR deleting student (%v) from Firestore DB: %v\n", s, err)
// return errors.Wrap(err, "Error in FirebaseDatabase.Delete()")
// }
// return nil
// }
This diff is collapsed.
Click to expand it.
assignment2/webhook.go
+
12
−
0
View file @
a6d48ffe
...
@@ -61,6 +61,18 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
...
@@ -61,6 +61,18 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
}
}
}
}
case
http
.
MethodDelete
:
err
:=
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
webhook
)
//decode to webhook
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
}
err
=
FBDelete
(
webhook
.
ID
)
if
err
!=
nil
{
fmt
.
Println
(
"Error: "
,
err
)
}
default
:
default
:
http
.
Error
(
w
,
"Method is invalid "
+
r
.
Method
,
http
.
StatusBadRequest
)
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