Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
d06e0247
Commit
d06e0247
authored
Sep 04, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #795 from mvpmvh/context_params
Context params
parents
2dfe1fc6
4d65330c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
2 deletions
+106
-2
controller.go
controller.go
+31
-2
controller_test.go
controller_test.go
+75
-0
No files found.
controller.go
View file @
d06e0247
...
@@ -382,8 +382,37 @@ func (c *Controller) GetStrings(key string) []string {
...
@@ -382,8 +382,37 @@ func (c *Controller) GetStrings(key string) []string {
return
[]
string
{}
return
[]
string
{}
}
}
// GetInt returns input value as int64.
// GetInt returns input as an int
func
(
c
*
Controller
)
GetInt
(
key
string
)
(
int64
,
error
)
{
func
(
c
*
Controller
)
GetInt
(
key
string
)
(
int
,
error
)
{
return
strconv
.
Atoi
(
c
.
Ctx
.
Input
.
Query
(
key
))
}
// GetInt8 return input as an int8
func
(
c
*
Controller
)
GetInt8
(
key
string
)
(
int8
,
error
)
{
i64
,
err
:=
strconv
.
ParseInt
(
c
.
Ctx
.
Input
.
Query
(
key
),
10
,
8
)
i8
:=
int8
(
i64
)
return
i8
,
err
}
// GetInt16 returns input as an int16
func
(
c
*
Controller
)
GetInt16
(
key
string
)
(
int16
,
error
)
{
i64
,
err
:=
strconv
.
ParseInt
(
c
.
Ctx
.
Input
.
Query
(
key
),
10
,
16
)
i16
:=
int16
(
i64
)
return
i16
,
err
}
// GetInt32 returns input as an int32
func
(
c
*
Controller
)
GetInt32
(
key
string
)
(
int32
,
error
)
{
i64
,
err
:=
strconv
.
ParseInt
(
c
.
Ctx
.
Input
.
Query
(
key
),
10
,
32
)
i32
:=
int32
(
i64
)
return
i32
,
err
}
// GetInt64 returns input value as int64.
func
(
c
*
Controller
)
GetInt64
(
key
string
)
(
int64
,
error
)
{
return
strconv
.
ParseInt
(
c
.
Ctx
.
Input
.
Query
(
key
),
10
,
64
)
return
strconv
.
ParseInt
(
c
.
Ctx
.
Input
.
Query
(
key
),
10
,
64
)
}
}
...
...
controller_test.go
0 → 100644
View file @
d06e0247
// Copyright 2014 beego Author. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
beego
import
(
"fmt"
"github.com/astaxie/beego/context"
)
func
ExampleGetInt
()
{
i
:=
&
context
.
BeegoInput
{
Params
:
map
[
string
]
string
{
"age"
:
"40"
}}
ctx
:=
&
context
.
Context
{
Input
:
i
}
ctrlr
:=
Controller
{
Ctx
:
ctx
}
val
,
_
:=
ctrlr
.
GetInt
(
"age"
)
fmt
.
Printf
(
"%T"
,
val
)
//Output: int
}
func
ExampleGetInt8
()
{
i
:=
&
context
.
BeegoInput
{
Params
:
map
[
string
]
string
{
"age"
:
"40"
}}
ctx
:=
&
context
.
Context
{
Input
:
i
}
ctrlr
:=
Controller
{
Ctx
:
ctx
}
val
,
_
:=
ctrlr
.
GetInt8
(
"age"
)
fmt
.
Printf
(
"%T"
,
val
)
//Output: int8
}
func
ExampleGetInt16
()
{
i
:=
&
context
.
BeegoInput
{
Params
:
map
[
string
]
string
{
"age"
:
"40"
}}
ctx
:=
&
context
.
Context
{
Input
:
i
}
ctrlr
:=
Controller
{
Ctx
:
ctx
}
val
,
_
:=
ctrlr
.
GetInt16
(
"age"
)
fmt
.
Printf
(
"%T"
,
val
)
//Output: int16
}
func
ExampleGetInt32
()
{
i
:=
&
context
.
BeegoInput
{
Params
:
map
[
string
]
string
{
"age"
:
"40"
}}
ctx
:=
&
context
.
Context
{
Input
:
i
}
ctrlr
:=
Controller
{
Ctx
:
ctx
}
val
,
_
:=
ctrlr
.
GetInt32
(
"age"
)
fmt
.
Printf
(
"%T"
,
val
)
//Output: int32
}
func
ExampleGetInt64
()
{
i
:=
&
context
.
BeegoInput
{
Params
:
map
[
string
]
string
{
"age"
:
"40"
}}
ctx
:=
&
context
.
Context
{
Input
:
i
}
ctrlr
:=
Controller
{
Ctx
:
ctx
}
val
,
_
:=
ctrlr
.
GetInt64
(
"age"
)
fmt
.
Printf
(
"%T"
,
val
)
//Output: int64
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment