Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Go Httpbin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Nix
Go Httpbin
Commits
ee985a5e
Unverified
Commit
ee985a5e
authored
Jul 3, 2019
by
Will McCutchen
Committed by
GitHub
Jul 3, 2019
Browse files
Options
Downloads
Plain Diff
Merge pull request #25 from mccutchen/cov-followups
Get code coverage back up
parents
f7f9d2e1
c694061e
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
httpbin/handlers.go
+1
-6
1 addition, 6 deletions
httpbin/handlers.go
httpbin/handlers_test.go
+17
-1
17 additions, 1 deletion
httpbin/handlers_test.go
httpbin/helpers.go
+3
-4
3 additions, 4 deletions
httpbin/helpers.go
with
22 additions
and
12 deletions
README.md
+
1
−
1
View file @
ee985a5e
...
...
@@ -5,7 +5,7 @@ A reasonably complete and well-tested golang port of [Kenneth Reitz][kr]'s
[

](https://godoc.org/github.com/mccutchen/go-httpbin)
[

](http://travis-ci.org/mccutchen/go-httpbin)
[

](http://
go
cov
er
.io/g
ithub.com
/mccutchen/go-httpbin
/httpbin
)
[

](http
s
://
code
cov.io/g
h
/mccutchen/go-httpbin)
## Usage
...
...
This diff is collapsed.
Click to expand it.
httpbin/handlers.go
+
1
−
6
View file @
ee985a5e
...
...
@@ -898,13 +898,8 @@ func (h *HTTPBin) DigestAuth(w http.ResponseWriter, r *http.Request) {
// UUID - responds with a generated UUID
func
(
h
*
HTTPBin
)
UUID
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
u
,
err
:=
uuidv4
()
if
err
!=
nil
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"Failed to generate uuid: %s"
,
err
),
http
.
StatusInternalServerError
)
return
}
resp
,
_
:=
json
.
Marshal
(
&
uuidResponse
{
UUID
:
u
,
UUID
:
u
uidv4
()
,
})
writeJSON
(
w
,
resp
,
http
.
StatusOK
)
}
...
...
This diff is collapsed.
Click to expand it.
httpbin/handlers_test.go
+
17
−
1
View file @
ee985a5e
...
...
@@ -54,7 +54,7 @@ func assertContentType(t *testing.T, w *httptest.ResponseRecorder, contentType s
func
assertBodyContains
(
t
*
testing
.
T
,
w
*
httptest
.
ResponseRecorder
,
needle
string
)
{
if
!
strings
.
Contains
(
w
.
Body
.
String
(),
needle
)
{
t
.
Fatalf
(
"expected string %
v
in body"
,
needle
)
t
.
Fatalf
(
"expected string %
q
in body
%q
"
,
needle
,
w
.
Body
.
String
()
)
}
}
...
...
@@ -2254,6 +2254,22 @@ func TestBase64(t *testing.T) {
"/base64/decode/"
+
randStringBytes
(
Base64MaxLen
+
1
),
"Cannot handle input"
,
},
{
"/base64/"
,
"No input data"
,
},
{
"/base64/decode/"
,
"No input data"
,
},
{
"/base64/decode/dmFsaWRfYmFzZTY0X2VuY29kZWRfc3RyaW5n/extra"
,
"Invalid URL"
,
},
{
"/base64/unknown/dmFsaWRfYmFzZTY0X2VuY29kZWRfc3RyaW5n"
,
"Invalid operation: unknown"
,
},
}
for
_
,
test
:=
range
errorTests
{
...
...
This diff is collapsed.
Click to expand it.
httpbin/helpers.go
+
3
−
4
View file @
ee985a5e
...
...
@@ -236,16 +236,15 @@ func sha1hash(input string) string {
return
fmt
.
Sprintf
(
"%x"
,
h
.
Sum
([]
byte
(
input
)))
}
func
uuidv4
()
(
string
,
error
)
{
func
uuidv4
()
string
{
buff
:=
make
([]
byte
,
16
)
_
,
err
:=
rand
.
Read
(
buff
[
:
])
if
err
!=
nil
{
return
""
,
err
panic
(
err
)
}
buff
[
6
]
=
(
buff
[
6
]
&
0x0f
)
|
0x40
// Version 4
buff
[
8
]
=
(
buff
[
8
]
&
0x3f
)
|
0x80
// Variant 10
uuid
:=
fmt
.
Sprintf
(
"%x-%x-%x-%x-%x"
,
buff
[
0
:
4
],
buff
[
4
:
6
],
buff
[
6
:
8
],
buff
[
8
:
10
],
buff
[
10
:
])
return
uuid
,
nil
return
fmt
.
Sprintf
(
"%x-%x-%x-%x-%x"
,
buff
[
0
:
4
],
buff
[
4
:
6
],
buff
[
6
:
8
],
buff
[
8
:
10
],
buff
[
10
:
])
}
// base64Helper - describes the base64 operation (encode|decode) and input data
...
...
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