123456789101112131415161718192021222324252627282930313233343536 |
- package api
-
- import (
- "fmt"
- )
-
- const (
- EnUS = 1
- ZhCN = 2
- )
-
- type CommonParams struct {
- TargetStr string `form:"lang"`
- Target int
- Page int `form:"page"`
- Limit int `form:"limit"`
- }
-
- 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
- }
|