Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
0a4fb1f0
提交
0a4fb1f0
authored
9月 25, 2018
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add documenation.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
dd7c66f2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
32 行增加
和
0 行删除
+32
-0
cidbase.go
core/commands/cmdenv/cidbase.go
+32
-0
没有找到文件。
core/commands/cmdenv/cidbase.go
浏览文件 @
0a4fb1f0
...
...
@@ -12,6 +12,14 @@ import (
var
OptionCidBase
=
cmdkit
.
StringOption
(
"cid-base"
,
"mbase"
,
"Multi-base to use to encode version 1 CIDs in output."
)
var
OptionOutputCidV1
=
cmdkit
.
BoolOption
(
"output-cidv1"
,
"Upgrade CID version 0 to version 1 in output."
)
// CidBaseHandler is a helper class to process the `--cid-base` and
// `--output-cidv1` options. In the future it may also be used to
// process relevant config settings.
//
// Several of its methods return the class itself in order to allow
// easy chaining, a typical usage would be
// `cmdenv.NewCidBaseHandler(req).UseGlobal().Proc()` or
// `cmdenv.NewCidBaseHandlerLegacy(req).Proc()`.
type
CidBaseHandler
struct
{
base
string
upgrade
bool
...
...
@@ -20,6 +28,7 @@ type CidBaseHandler struct {
enc
*
cidenc
.
Encoder
}
// NewCidBaseHandler created a a CidBaseHandler from a request
func
NewCidBaseHandler
(
req
*
cmds
.
Request
)
*
CidBaseHandler
{
h
:=
&
CidBaseHandler
{}
h
.
base
,
_
=
req
.
Options
[
"cid-base"
]
.
(
string
)
...
...
@@ -28,6 +37,8 @@ func NewCidBaseHandler(req *cmds.Request) *CidBaseHandler {
return
h
}
// NewCidBaseHandlerLegacy created a a CidBaseHandler from a request
// using the old commands library
func
NewCidBaseHandlerLegacy
(
req
oldcmds
.
Request
)
*
CidBaseHandler
{
h
:=
&
CidBaseHandler
{}
h
.
base
,
_
,
_
=
req
.
Option
(
"cid-base"
)
.
String
()
...
...
@@ -36,11 +47,17 @@ func NewCidBaseHandlerLegacy(req oldcmds.Request) *CidBaseHandler {
return
h
}
// UseGlobal enables the use of the global default. This is somewhat
// of a hack and should be used with care. In particular it should
// only be used on the client side and not the server side.
func
(
h
*
CidBaseHandler
)
UseGlobal
()
*
CidBaseHandler
{
h
.
enc
=
&
cidenc
.
Default
return
h
}
// Proc processes the `--cid-base` and `--output-cidv1` options. If
// UseGlobal was enabled it will change the value of the global
// default.
func
(
h
*
CidBaseHandler
)
Proc
()
(
*
CidBaseHandler
,
error
)
{
var
e
cidenc
.
Encoder
=
cidenc
.
Default
if
h
.
base
!=
""
{
...
...
@@ -63,10 +80,19 @@ func (h *CidBaseHandler) Proc() (*CidBaseHandler, error) {
return
h
,
nil
}
// Encoder returns a copy of the underlying Encoder
func
(
h
*
CidBaseHandler
)
Encoder
()
cidenc
.
Encoder
{
return
*
h
.
enc
}
// EncoderFromPath returns a a new Encoder that will format Cid like
// the one in the path if the `--cid-base` option is not used. (If
// the `--cid-base` is used then a copy of the base encoder will be
// returned.) In particular: if the path contains a version 1 CID
// then all CIDs will be outputting using the same multibase. if the
// path contains a version 0 CID then version 0 CIDs will be outputted
// as is and version1 cids will use the multibase from the base
// encoder
func
(
h
*
CidBaseHandler
)
EncoderFromPath
(
p
string
)
cidenc
.
Encoder
{
if
h
.
base
==
""
{
enc
,
_
:=
cidenc
.
FromPath
(
*
h
.
enc
,
p
)
...
...
@@ -76,6 +102,12 @@ func (h *CidBaseHandler) EncoderFromPath(p string) cidenc.Encoder {
}
}
// EncoderWithOverride returns a new encoder that will use the setting
// from the base encoder unless it is a CID that was specified on the
// command line and the `--cid-base` option was not used. (If the
// `--cid-base` is used then a copy of the base encoder will be
// returned.) In that case the same CID string as specified on the
// command line will be used.
func
(
h
*
CidBaseHandler
)
EncoderWithOverride
()
cidenc
.
Interface
{
if
h
.
base
==
""
{
enc
:=
cidenc
.
NewOverride
(
*
h
.
enc
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论