Skip to content

Commit

Permalink
パスパラメータの取得関数のシグネチャを変更
Browse files Browse the repository at this point in the history
  • Loading branch information
hikaru7719 committed Jun 14, 2021
1 parent e1fc646 commit eadac6f
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,8 @@ func NewRequest(r *http.Request, params map[string]interface{}) *http.Request {
return r.WithContext(ctx)
}

type Context struct {
ctx context.Context
}

func NewContext(ctx context.Context) *Context {
return &Context{ctx: ctx}
}

func Param(r *http.Request) *Context {
ctx := r.Context()
return NewContext(ctx)
}

func (c *Context) getString(key string) string {
if m, ok := c.ctx.Value(tinyrouterKey).(map[string]interface{}); !ok {
func Param(r *http.Request, key string) string {
if m, ok := r.Context().Value(tinyrouterKey).(map[string]interface{}); !ok {
return ""
} else if v, ok := m[key]; !ok {
return ""
Expand All @@ -46,15 +33,3 @@ func (c *Context) getString(key string) string {
return str
}
}

func (c *Context) getInt(key string) int {
if m, ok := c.ctx.Value(tinyrouterKey).(map[string]interface{}); !ok {
return 0
} else if v, ok := m[key]; !ok {
return 0
} else if num, ok := v.(int); !ok {
return 0
} else {
return num
}
}

0 comments on commit eadac6f

Please sign in to comment.