http urls monitor.

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package api
  2. import (
  3. "fmt"
  4. )
  5. // language code
  6. const (
  7. EnUS = 1
  8. ZhCN = 2
  9. )
  10. // CommonParams page and lang info
  11. type CommonParams struct {
  12. TargetStr string `form:"lang"`
  13. Target int
  14. Page int `form:"page"`
  15. Limit int `form:"limit"`
  16. }
  17. // Check param check
  18. func (cp *CommonParams) Check() error {
  19. switch cp.TargetStr {
  20. case "", "en-US":
  21. cp.Target = EnUS
  22. case "zh-CN":
  23. cp.Target = ZhCN
  24. default:
  25. return fmt.Errorf("Unexpected target param: %s", cp.TargetStr)
  26. }
  27. if cp.Limit == 0 {
  28. cp.Limit = 10
  29. }
  30. if cp.Page == 0 {
  31. cp.Page = 1
  32. }
  33. return nil
  34. }