1
1
package org .ivovk .connect_rpc_scala
2
2
3
3
import cats .implicits .*
4
- import com .google .api .HttpRule
4
+ import com .google .api .http .{ CustomHttpPattern , HttpRule }
5
5
import org .http4s .{Method , Request , Uri }
6
6
import org .ivovk .connect_rpc_scala
7
7
import org .ivovk .connect_rpc_scala .grpc .MethodRegistry
@@ -60,7 +60,7 @@ object TranscodingUrlMatcher {
60
60
Node (
61
61
variableDef,
62
62
segment,
63
- mkTree(entries.map(e => e.copy(pattern = e.pattern.splitAt(1 )._2)).toVector ),
63
+ mkTree(entries.map(e => e.copy(pattern = e.pattern.splitAt(1 )._2))),
64
64
)
65
65
)
66
66
}
@@ -74,7 +74,7 @@ object TranscodingUrlMatcher {
74
74
val result = collection.mutable.LinkedHashMap .empty[B , Vector [A ]]
75
75
76
76
it.foreach { elem =>
77
- val key = f(elem)
77
+ val key = f(elem)
78
78
val vec = result.getOrElse(key, Vector .empty)
79
79
result.update(key, vec :+ elem)
80
80
}
@@ -106,7 +106,7 @@ object TranscodingUrlMatcher {
106
106
): TranscodingUrlMatcher [F ] = {
107
107
val entries = methods.flatMap { method =>
108
108
method.httpRule.fold(List .empty[Entry ]) { httpRule =>
109
- val additionalBindings = httpRule.getAdditionalBindingsList.asScala .toList
109
+ val additionalBindings = httpRule.additionalBindings .toList
110
110
111
111
(httpRule :: additionalBindings).map { rule =>
112
112
val (httpMethod, pattern) = extractMethodAndPattern(rule)
@@ -126,13 +126,13 @@ object TranscodingUrlMatcher {
126
126
}
127
127
128
128
private def extractMethodAndPattern (rule : HttpRule ): (Option [Method ], Uri .Path ) = {
129
- val (method, str) = rule.getPatternCase match
130
- case HttpRule .PatternCase . GET => (Method .GET .some, rule.getGet )
131
- case HttpRule .PatternCase . PUT => (Method .PUT .some, rule.getPut )
132
- case HttpRule .PatternCase . POST => (Method .POST .some, rule.getPost )
133
- case HttpRule .PatternCase . DELETE => (Method .DELETE .some, rule.getDelete )
134
- case HttpRule .PatternCase . PATCH => (Method .PATCH .some, rule.getPatch )
135
- case HttpRule .PatternCase . CUSTOM = > (none, rule.getCustom.getPath )
129
+ val (method, str) = rule.pattern match
130
+ case HttpRule .Pattern . Get (value) => (Method .GET .some, value )
131
+ case HttpRule .Pattern . Put (value) => (Method .PUT .some, value )
132
+ case HttpRule .Pattern . Post (value) => (Method .POST .some, value )
133
+ case HttpRule .Pattern . Delete (value) => (Method .DELETE .some, value )
134
+ case HttpRule .Pattern . Patch (value) => (Method .PATCH .some, value )
135
+ case HttpRule .Pattern . Custom ( CustomHttpPattern (kind, value, _)) if kind == " * " = > (none, value )
136
136
case other => throw new RuntimeException (s " Unsupported pattern case $other (Rule: $rule) " )
137
137
138
138
val path = Uri .Path .unsafeFromString(str).dropEndsWithSlash
@@ -169,13 +169,13 @@ class TranscodingUrlMatcher[F[_]](
169
169
JObject (groupFields(pathVars)),
170
170
JObject (groupFields(queryParams))
171
171
).some
172
- case RootNode (children) =>
173
- children.colFirst(doMatch(_, path, pathVars))
174
172
case _ => none
175
173
}
176
174
}
177
175
178
- doMatch(tree, req.uri.path.segments.toList, List .empty)
176
+ val path = req.uri.path.segments.toList
177
+
178
+ tree.children.colFirst(doMatch(_, path, Nil ))
179
179
}
180
180
181
181
}
0 commit comments