/vendor/github.com/webx-top/echo/echo_host.go

https://github.com/admpub/nging · Go · 43 lines · 41 code · 2 blank · 0 comment · 2 complexity · ea67ef666087f4e4b4919f93f7e33f51 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 {
  17. return ``
  18. }
  19. return t.prefix + t.echo.URI(handler, params...)
  20. }
  21. func (h *Host) Host(args ...interface{}) (r TypeHost) {
  22. if h.group == nil || h.group.host == nil {
  23. return
  24. }
  25. r.echo = h.group.echo
  26. r.router = h.Router
  27. if len(args) != 1 {
  28. r.prefix = h.group.host.Format(args...)
  29. return
  30. }
  31. switch v := args[0].(type) {
  32. case map[string]interface{}:
  33. r.prefix = h.group.host.FormatMap(v)
  34. case H:
  35. r.prefix = h.group.host.FormatMap(v)
  36. default:
  37. r.prefix = h.group.host.Format(args...)
  38. }
  39. return
  40. }