Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

specified a version for certain deprecations #408

Merged
merged 1 commit into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions default_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ func (d *DefaultContext) Param(key string) string {
// ParamInt tries to convert the requested parameter to
// an int. It will return an error if there is a problem.
func (d *DefaultContext) ParamInt(key string) (int, error) {
warningMsg := "Context#ParamInt is deprecated, and will be removed in v0.9.0."

_, file, no, ok := runtime.Caller(1)
if ok {
warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no)
}

d.Logger().Warn(warningMsg)

k := d.Params().Get(key)
i, err := strconv.Atoi(k)
return i, errors.WithMessage(err, fmt.Sprintf("could not convert %s to an int", k))
Expand All @@ -78,11 +87,11 @@ func (d *DefaultContext) Set(key string, value interface{}) {

// Get is deprecated. Please use Value instead.
func (d *DefaultContext) Get(key string) interface{} {
warningMsg := "Context#Get is deprecated. Please use Context#Value instead."
warningMsg := "Context#Get is deprecated, and will be removed in v0.9.0. Please use Context#Value instead."

_, file, no, ok := runtime.Caller(1)
if ok {
warningMsg = fmt.Sprintf("Context#Get is deprecated. Please use Context#Value instead. Called from %s:%d", file, no)
warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no)
}

d.Logger().Warn(warningMsg)
Expand Down
9 changes: 4 additions & 5 deletions default_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ func Test_DefaultContext_Param(t *testing.T) {

func Test_DefaultContext_ParamInt(t *testing.T) {
r := require.New(t)
c := DefaultContext{
params: url.Values{
"name": []string{"Mark"},
"id": []string{"1"},
},
c := basicContext()
c.params = url.Values{
"name": []string{"Mark"},
"id": []string{"1"},
}

id, err := c.ParamInt("id")
Expand Down