暂无描述

main.go 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package router
  2. import (
  3. "net/http"
  4. )
  5. type route struct {
  6. Pattern string
  7. Handler http.Handler
  8. }
  9. //Routes array of route
  10. type Routes []route
  11. func (routes *Routes) add(pattern string, handler http.Handler) {
  12. append(routes, route[
  13. pattern,
  14. handler,
  15. ])
  16. }
  17. // func findURLMatch(data urls, url string) string {
  18. // for _, element := range data {
  19. // when := element.When
  20. // pattern := toRegex(when)
  21. // items := regexSubmatch(pattern, url)
  22. // if items[0] == url {
  23. // urlProxy := replaceStringsURL(items, element.To)
  24. // return urlProxy
  25. // }
  26. // }
  27. // return ""
  28. // }
  29. // func readFile(filePath string) urls {
  30. // file, err1 := ioutil.ReadFile(filePath)
  31. // if err1 != nil {
  32. // fmt.Printf("Error while reading file %s\n", filePath)
  33. // fmt.Printf("File error: %v\n", err1)
  34. // os.Exit(1)
  35. // }
  36. // var urls []urlObject
  37. // err2 := json.Unmarshal(file, &urls)
  38. // if err2 != nil {
  39. // fmt.Println("error:", err2)
  40. // os.Exit(1)
  41. // }
  42. // return urls
  43. // }
  44. // //PatternURL coloca barra no final de url se não tiver
  45. // func patternURL(url string) string {
  46. // lastChar := url[len(url)-1:]
  47. // if lastChar != "/" {
  48. // url = url + "/"
  49. // }
  50. // return url
  51. // }
  52. // //ToRegex converte uma expressao imputada em expressão do go
  53. // func toRegex(regex string) *regexp.Regexp {
  54. // return regexp.MustCompile(`(?m)` + regex)
  55. // }
  56. // //RegexSubmatch cria os matches aplicando a padrão de regex inputado
  57. // func regexSubmatch(pattern *regexp.Regexp, str string) []string {
  58. // data := []string{""}
  59. // items := pattern.FindAllStringSubmatch(str, -1)
  60. // if len(items) > 0 {
  61. // data = items[0]
  62. // }
  63. // return data
  64. // }
  65. // //ReplaceStringsURL alterar a url imputada colocando as variaveis da url inserida
  66. // func replaceStringsURL(items []string, urlPattern string) string {
  67. // for index, element := range items {
  68. // urlPattern = strings.Replace(urlPattern, "$"+strconv.Itoa(index), element, -1)
  69. // }
  70. // return urlPattern
  71. // }