/echo_host.go

https://github.com/webx-top/echo · Go · 47 lines · 45 code · 2 blank · 0 comment · 4 complexity · 972dba3185c20d13618663058a542850 MD5 · raw file

  1. package echo
  2. type (
  3. Host struct {
  4. head Handler
  5. group *Group
  6. groups map[string]*Group
  7. Router *Router
  8. }
  9. TypeHost struct {
  10. prefix string
  11. router *Router
  12. echo *Echo
  13. }
  14. )
  15. func (t TypeHost) URI(handler interface{}, params ...interface{}) string {
  16. if t.router == nil || t.echo == nil {
  17. return ``
  18. }
  19. return t.prefix + t.echo.URI(handler, params...)
  20. }
  21. func (t TypeHost) String() string {
  22. return t.prefix
  23. }
  24. func (h *Host) Host(args ...interface{}) (r TypeHost) {
  25. if h.group == nil || h.group.host == nil {
  26. return
  27. }
  28. r.echo = h.group.echo
  29. r.router = h.Router
  30. if len(args) != 1 {
  31. r.prefix = h.group.host.Format(args...)
  32. return
  33. }
  34. switch v := args[0].(type) {
  35. case map[string]interface{}:
  36. r.prefix = h.group.host.FormatMap(v)
  37. case H:
  38. r.prefix = h.group.host.FormatMap(v)
  39. default:
  40. r.prefix = h.group.host.Format(args...)
  41. }
  42. return
  43. }