forked from TrueCloudLab/frostfs-http-gw
[#142] Support resolving container nicename
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
2b780c1772
commit
a42606742a
14 changed files with 458 additions and 74 deletions
21
utils/util.go
Normal file
21
utils/util.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/nspcc-dev/neofs-http-gw/resolver"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
)
|
||||
|
||||
// GetContainerID decode container id, if it's not a valid container id
|
||||
// then trey to resolve name using provided resolver.
|
||||
func GetContainerID(ctx context.Context, containerID string, resolver *resolver.ContainerResolver) (*cid.ID, error) {
|
||||
cnrID := new(cid.ID)
|
||||
err := cnrID.DecodeString(containerID)
|
||||
if err != nil {
|
||||
if resolver != nil {
|
||||
cnrID, err = resolver.Resolve(ctx, containerID)
|
||||
}
|
||||
}
|
||||
return cnrID, err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue