rambleraptor commented on code in PR #1174:
URL: https://github.com/apache/iceberg-go/pull/1174#discussion_r3391748384


##########
catalog/rest/endpoints.go:
##########
@@ -0,0 +1,173 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package rest
+
+import (
+       "fmt"
+       "net/http"
+       "strings"
+)
+
+// ErrEndpointNotSupported indicates the server did not advertise a REST 
endpoint
+// required by the requested operation. It wraps [ErrRESTError].
+var ErrEndpointNotSupported = fmt.Errorf("%w: endpoint not supported by 
server", ErrRESTError)
+
+// pathPrefix is the part of every endpoint template already encoded in the 
base
+// URI (API version plus optional catalog prefix); reqPath strips it.
+const pathPrefix = "/v1/{prefix}"
+
+// endpoint identifies a REST catalog operation by HTTP method and path 
template
+// (e.g. "GET /v1/{prefix}/namespaces"). Servers advertise the endpoints they
+// support in the config response so the client can negotiate capabilities.
+//
+// Each endpoint both gates capability and builds the request path (see
+// [endpoint.reqPath]), making it the single source of truth for its operation.
+type endpoint struct {
+       method string
+       path   string
+}
+
+func (e endpoint) String() string { return e.method + " " + e.path }
+
+// reqPath renders the request path relative to the base URI, substituting 
params
+// in order for the "{...}" placeholders that follow [pathPrefix].
+func (e endpoint) reqPath(params ...string) []string {
+       segs := strings.Split(strings.TrimPrefix(e.path, pathPrefix+"/"), "/")
+
+       out := make([]string, len(segs))
+       p := 0
+       for i, s := range segs {
+               if strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}") {

Review Comment:
   Yep, let's return an error. I really don't like panics.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to