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
7acefc61
Commit
7acefc61
authored
5 years ago
by
Hans Kristian Hoel
Browse files
Options
Downloads
Patches
Plain Diff
cratet a QueryGet function to prevent duplication in code
parent
591a1812
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
assignment2/cmd/main.go
+6
-6
6 additions, 6 deletions
assignment2/cmd/main.go
assignment2/handler.go
+22
-28
22 additions, 28 deletions
assignment2/handler.go
with
28 additions
and
34 deletions
assignment2/cmd/main.go
+
6
−
6
View file @
7acefc61
This diff is collapsed.
Click to expand it.
assignment2/handler.go
+
22
−
28
View file @
7acefc61
package
assignment2
import
(
"net/http"
"fmt"
"net/http"
)
func
HandlerNil
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
//standar default respons
...
...
@@ -10,31 +10,28 @@ func HandlerNil(w http.ResponseWriter, r *http.Request) { //standar default res
http
.
Error
(
w
,
"Invalid request"
,
http
.
StatusBadRequest
)
}
func
HandlerCommits
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
QueryGet
(
s
string
,
t
string
,
r
*
http
.
Request
)
string
{
limi
t
:=
r
.
URL
.
Query
()
.
Get
(
"limit"
)
// Reads limit
if
limi
t
==
""
{
// cheks if there exist an limit
limit
=
"5"
// sets limit to 5
tes
t
:=
r
.
URL
.
Query
()
.
Get
(
s
)
if
tes
t
==
""
{
test
=
t
}
return
test
auth
:=
r
.
URL
.
Query
()
.
Get
(
"auth"
)
// Reads auth
if
auth
==
""
{
// cheks if there exist an auth
auth
=
"false"
// sets auth to false
}
func
HandlerCommits
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
limit
:=
QueryGet
(
"limit"
,
"5"
,
r
)
auth
:=
QueryGet
(
"auth"
,
"false"
,
r
)
}
func
HandlerLanguages
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
limit
:=
r
.
URL
.
Query
()
.
Get
(
"limit"
)
// Reads limit
if
limit
==
""
{
// cheks if there exist an limit
limit
=
"5"
// sets limit to 5
}
limit
:=
QueryGet
(
"limit"
,
"5"
,
r
)
auth
:=
r
.
URL
.
Query
()
.
Get
(
"auth"
)
// Reads auth
if
auth
==
""
{
// cheks if there exist an auth
auth
=
"false"
// sets auth to false
}
auth
:=
QueryGet
(
"auth"
,
"false"
,
r
)
}
...
...
@@ -45,10 +42,7 @@ func HandlerIssues (w http.ResponseWriter, r *http.Request) {
// error
}
auth
:=
r
.
URL
.
Query
()
.
Get
(
"auth"
)
// Reads auth
if
auth
==
""
{
// cheks if there exist an auth
auth
=
"false"
// sets auth to false
}
auth
:=
QueryGet
(
"auth"
,
"false"
,
r
)
}
...
...
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