ApiRouteProperties.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package cn.exlive.exbooter.configure;
  18. import org.apache.commons.lang.StringUtils;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. import java.util.Optional;
  22. import java.util.Set;
  23. import javax.validation.constraints.NotBlank;
  24. import lombok.Getter;
  25. import lombok.Setter;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.springframework.boot.context.properties.ConfigurationProperties;
  28. import org.springframework.context.annotation.Configuration;
  29. /**
  30. * <pre>
  31. *
  32. * Created by zhenqin.
  33. * User: zhenqin
  34. * Date: 2022/4/25
  35. * Time: 下午7:12
  36. *
  37. * </pre>
  38. *
  39. * @author zhenqin
  40. */
  41. @Slf4j
  42. @Setter
  43. @Getter
  44. @Configuration
  45. @ConfigurationProperties(prefix = "exbooter")
  46. public class ApiRouteProperties {
  47. /**
  48. * 绑定的 tasks
  49. */
  50. Map<String, ApiRoute> routers;
  51. /**
  52. * 排除的地址
  53. */
  54. String excludePatterns = "";
  55. /**
  56. * 代理的总路由,这里默认是 /, 实际在 DDH 中访问是 /jdh/
  57. */
  58. String servletPath = "/";
  59. public ApiRouteProperties() {
  60. }
  61. @NotBlank
  62. public String getServletPath() {
  63. return Optional.ofNullable(StringUtils.trimToNull(servletPath)).orElse("/");
  64. }
  65. /**
  66. * 返回所有的 task Name
  67. * @return
  68. */
  69. public Set<String> getAllRouters() {
  70. if (routers == null) {
  71. routers = new HashMap<>();
  72. }
  73. return routers.keySet();
  74. }
  75. public Map<String, ApiRoute> getRouters() {
  76. getAllRouters();
  77. return routers;
  78. }
  79. }