@@ -72,17 +72,8 @@ func (c *ShardRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
7272 shard := ShardFromContext (req .Context ())
7373 if ! shard .Empty () {
7474 req = req .Clone (req .Context ())
75- path , err := generatePath (req .URL .Path , shard )
76- if err != nil {
77- return nil , err
78- }
79- req .URL .Path = path
80-
81- rawPath , err := generatePath (req .URL .RawPath , shard )
82- if err != nil {
83- return nil , err
84- }
85- req .URL .RawPath = rawPath
75+ req .URL .Path = generatePath (req .URL .Path , shard )
76+ req .URL .RawPath = generatePath (req .URL .RawPath , shard )
8677 }
8778 return c .delegate .RoundTrip (req )
8879}
@@ -92,24 +83,24 @@ func (c *ShardRoundTripper) WrappedRoundTripper() http.RoundTripper {
9283}
9384
9485// generatePath formats the request path to target the specified shard.
95- func generatePath (originalPath string , shard clientshard.Name ) ( string , error ) {
86+ func generatePath (originalPath string , shard clientshard.Name ) string {
9687 // if the originalPath already has the shard then the path was already modified and no change needed
9788 if strings .HasPrefix (originalPath , shard .Path ()) {
98- return originalPath , nil
89+ return originalPath
9990 }
10091 // if the originalPath already has a shard set just overwrite it to the given one
10192 if strings .HasPrefix (originalPath , "/shards" ) {
10293 matches := shardNameRegex .FindStringSubmatch (originalPath )
10394 if len (matches ) >= 2 {
10495 // replace /shards/$oldName/reminder with /shards/$newName/reminder
105- return strings .Replace (originalPath , clientshard .New (matches [1 ]).Path (), shard .Path (), 1 ), nil
96+ return strings .Replace (originalPath , clientshard .New (matches [1 ]).Path (), shard .Path (), 1 )
10697 } else {
10798 // the path is either /shards/name/ or /shards/name
10899 path := shard .Path ()
109100 if originalPath [len (originalPath )- 1 ] == '/' {
110101 path += "/"
111102 }
112- return path , nil
103+ return path
113104 }
114105 }
115106
@@ -121,7 +112,7 @@ func generatePath(originalPath string, shard clientshard.Name) (string, error) {
121112 }
122113 // finally append the original path
123114 path += originalPath
124- return path , nil
115+ return path
125116}
126117
127118// WithDefaultShardRoundTripper wraps an existing config's with DefaultShardRoundTripper
0 commit comments