route.go 747 B

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package route // import "miniflux.app/v2/internal/http/route"
  4. import (
  5. "strconv"
  6. "github.com/gorilla/mux"
  7. )
  8. // Path returns the defined route based on given arguments.
  9. func Path(router *mux.Router, name string, args ...any) string {
  10. route := router.Get(name)
  11. if route == nil {
  12. panic("route not found: " + name)
  13. }
  14. var pairs []string
  15. for _, arg := range args {
  16. switch param := arg.(type) {
  17. case string:
  18. pairs = append(pairs, param)
  19. case int64:
  20. pairs = append(pairs, strconv.FormatInt(param, 10))
  21. }
  22. }
  23. result, err := route.URLPath(pairs...)
  24. if err != nil {
  25. panic(err)
  26. }
  27. return result.String()
  28. }