Add bookmark in persistence layer
This commit is contained in:
@@ -51,6 +51,18 @@ func ParamInt(r *http.Request, param string, def int) int {
|
||||
return int(value)
|
||||
}
|
||||
|
||||
func ParamInt64(r *http.Request, param string, def int64) int64 {
|
||||
v := ParamString(r, param)
|
||||
if v == "" {
|
||||
return def
|
||||
}
|
||||
value, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func ParamInts(r *http.Request, param string) []int {
|
||||
pStr := ParamStrings(r, param)
|
||||
ints := make([]int, 0, len(pStr))
|
||||
|
||||
@@ -98,6 +98,24 @@ var _ = Describe("Request Helpers", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ParamInt64", func() {
|
||||
BeforeEach(func() {
|
||||
r = httptest.NewRequest("GET", "/ping?i=123&inv=123.45", nil)
|
||||
})
|
||||
|
||||
It("returns default value if param does not exist", func() {
|
||||
Expect(ParamInt64(r, "xx", 999)).To(Equal(int64(999)))
|
||||
})
|
||||
|
||||
It("returns default value if param is an invalid int", func() {
|
||||
Expect(ParamInt64(r, "inv", 999)).To(Equal(int64(999)))
|
||||
})
|
||||
|
||||
It("returns parsed time", func() {
|
||||
Expect(ParamInt64(r, "i", 999)).To(Equal(int64(123)))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ParamInts", func() {
|
||||
BeforeEach(func() {
|
||||
r = httptest.NewRequest("GET", "/ping?i=123&i=456", nil)
|
||||
|
||||
Reference in New Issue
Block a user