12345678910111213141516171819202122232425262728293031323334353637383940 |
- package api
-
- import (
- "fmt"
- )
-
- // language code
- const (
- EnUS = 1
- ZhCN = 2
- )
-
- // CommonParams page and lang info
- type CommonParams struct {
- TargetStr string `form:"lang"`
- Target int
- Page int `form:"page"`
- Limit int `form:"limit"`
- }
-
- // Check param check
- func (cp *CommonParams) Check() error {
- switch cp.TargetStr {
- case "", "en-US":
- cp.Target = EnUS
- case "zh-CN":
- cp.Target = ZhCN
- default:
- return fmt.Errorf("Unexpected target param: %s", cp.TargetStr)
- }
-
- if cp.Limit == 0 {
- cp.Limit = 10
- }
- if cp.Page == 0 {
- cp.Page = 1
- }
- return nil
- }
|