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
857667d0
Commit
857667d0
authored
5 years ago
by
Hans Kristian Hoel
Browse files
Options
Downloads
Patches
Plain Diff
traing to make webhooks work
parent
385b0af1
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
assignment2/commit.go
+5
-0
5 additions, 0 deletions
assignment2/commit.go
assignment2/go.mod
+0
-2
0 additions, 2 deletions
assignment2/go.mod
assignment2/structs.go
+9
-9
9 additions, 9 deletions
assignment2/structs.go
assignment2/webhook.go
+13
-0
13 additions, 0 deletions
assignment2/webhook.go
with
27 additions
and
11 deletions
assignment2/commit.go
+
5
−
0
View file @
857667d0
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"net/http"
"net/http"
"sort"
"sort"
"strconv"
"strconv"
"time"
)
)
func
HandlerCommits
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
HandlerCommits
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
@@ -119,8 +120,12 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
...
@@ -119,8 +120,12 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
http
.
Header
.
Add
(
w
.
Header
(),
"Content-Type"
,
"application/json"
)
// makes the print look good
http
.
Header
.
Add
(
w
.
Header
(),
"Content-Type"
,
"application/json"
)
// makes the print look good
// Webhooks**********************
Payload
:=
&
WebhooksInvocation
{}
Payload
:=
&
WebhooksInvocation
{}
Payload
.
Event
=
"Commits"
Payload
.
Event
=
"Commits"
Payload
.
Time
=
time
.
Now
()
Payload
.
Params
=
"Limit = "
+
limit
+
"and Auth = "
+
auth
json
.
NewEncoder
(
w
)
.
Encode
(
C
)
// encode C
json
.
NewEncoder
(
w
)
.
Encode
(
C
)
// encode C
...
...
This diff is collapsed.
Click to expand it.
assignment2/go.mod
+
0
−
2
View file @
857667d0
module assignment2
module assignment2
go 1.13
go 1.13
// +heroku goVersion go1.13
This diff is collapsed.
Click to expand it.
assignment2/structs.go
+
9
−
9
View file @
857667d0
...
@@ -56,15 +56,15 @@ type WebhookRegistration struct {
...
@@ -56,15 +56,15 @@ type WebhookRegistration struct {
Time
time
.
Time
`json:"time"`
Time
time
.
Time
`json:"time"`
}
}
type
Webhooks
struct
{
//
type Webhooks struct {
ID
int
`json:"id"`
//
ID int `json:"id"`
Event
string
`json:"Event"`
//
Event string `json:"Event"`
URL
string
`json:"url"`
//
URL string `json:"url"`
Time
float64
`json:"time"`
//
Time float64 `json:"time"`
}
//
}
type
WebhooksInvocation
struct
{
type
WebhooksInvocation
struct
{
Event
string
`json:"event"`
Event
string
`json:"event"`
Params
[]
string
`json:"params"`
Params
string
`json:"params"`
Time
float64
`json:"time"`
Time
time
.
Time
`json:"time"`
}
}
This diff is collapsed.
Click to expand it.
assignment2/webhook.go
+
13
−
0
View file @
857667d0
...
@@ -13,6 +13,11 @@ import (
...
@@ -13,6 +13,11 @@ import (
var
webhooks
[]
WebhookRegistration
//Webhook DB
var
webhooks
[]
WebhookRegistration
//Webhook DB
var
IDNum
=
1
var
IDNum
=
1
/*
Handles webhook registration (POST) and lookup (GET) requests.
Expects WebhookRegistration struct body in request.
*/
func
WebhookHandeler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
WebhookHandeler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
switch
r
.
Method
{
switch
r
.
Method
{
...
@@ -44,6 +49,10 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
...
@@ -44,6 +49,10 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
}
}
/*
Invokes the web service to trigger event. Currently only responds to POST requests.
*/
func
ServiceHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
ServiceHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
switch
r
.
Method
{
switch
r
.
Method
{
...
@@ -57,6 +66,10 @@ func ServiceHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -57,6 +66,10 @@ func ServiceHandler(w http.ResponseWriter, r *http.Request) {
}
}
}
}
/*
Calls given URL with given content and awaits response (status and body).
*/
func
CallUrl
(
url
string
,
content
string
)
{
func
CallUrl
(
url
string
,
content
string
)
{
fmt
.
Println
(
"Attempting invocation of url "
+
url
+
"..."
)
fmt
.
Println
(
"Attempting invocation of url "
+
url
+
"..."
)
res
,
err
:=
http
.
Post
(
url
,
"string"
,
bytes
.
NewReader
([]
byte
(
content
)))
res
,
err
:=
http
.
Post
(
url
,
"string"
,
bytes
.
NewReader
([]
byte
(
content
)))
...
...
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