route.go 850 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package route // import "miniflux.app/http/route"
  5. import (
  6. "strconv"
  7. "github.com/gorilla/mux"
  8. "miniflux.app/logger"
  9. )
  10. // Path returns the defined route based on given arguments.
  11. func Path(router *mux.Router, name string, args ...interface{}) string {
  12. route := router.Get(name)
  13. if route == nil {
  14. logger.Fatal("[Route] Route not found: %s", name)
  15. }
  16. var pairs []string
  17. for _, arg := range args {
  18. switch param := arg.(type) {
  19. case string:
  20. pairs = append(pairs, param)
  21. case int64:
  22. pairs = append(pairs, strconv.FormatInt(param, 10))
  23. }
  24. }
  25. result, err := route.URLPath(pairs...)
  26. if err != nil {
  27. logger.Fatal("[Route] %v", err)
  28. }
  29. return result.String()
  30. }