alessandro-nori commented on code in PR #709:
URL: https://github.com/apache/iceberg-go/pull/709#discussion_r2765134926


##########
io/registry.go:
##########
@@ -0,0 +1,106 @@
+// 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 io
+
+import (
+       "context"
+       "fmt"
+       "maps"
+       "net/url"
+       "slices"
+       "sync"
+)
+
+type registry map[string]SchemeFactory
+
+func (r registry) getKeys() []string {
+       regMutex.Lock()
+       defer regMutex.Unlock()
+
+       return slices.Collect(maps.Keys(r))
+}
+
+func (r registry) set(scheme string, factory SchemeFactory) {
+       regMutex.Lock()
+       defer regMutex.Unlock()
+       r[scheme] = factory
+}
+
+func (r registry) get(scheme string) (SchemeFactory, bool) {
+       regMutex.Lock()
+       defer regMutex.Unlock()
+       factory, ok := r[scheme]
+
+       return factory, ok
+}
+
+func (r registry) remove(scheme string) {
+       regMutex.Lock()
+       defer regMutex.Unlock()
+       delete(r, scheme)
+}
+
+var (
+       regMutex        sync.Mutex
+       defaultRegistry = registry{}
+)
+
+// SchemeFactory is a function that creates an IO implementation for a given 
URI and properties.
+type SchemeFactory func(ctx context.Context, parsed *url.URL, props 
map[string]string) (IO, error)
+
+// Register adds a new scheme factory to the registry. If the scheme is 
already registered, it will be replaced.
+func Register(scheme string, factory SchemeFactory) {
+       if factory == nil {
+               panic("io: Register factory is nil")
+       }
+       defaultRegistry.set(scheme, factory)

Review Comment:
   That's a fair point. I just mirrored what was done in the `catalog` package 
but I think this is worth adding that check here



-- 
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