Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
24e1e6d1
提交
24e1e6d1
authored
10月 20, 2014
作者:
Henry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
config: custom AutoUpdate type for validity
上级
8d41021b
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
96 行增加
和
13 行删除
+96
-13
version.go
config/version.go
+59
-12
version_test.go
config/version_test.go
+36
-0
updates.go
updates/updates.go
+1
-1
没有找到文件。
config/version.go
浏览文件 @
24e1e6d1
package
config
import
(
"errors"
"strconv"
"strings"
"time"
)
...
...
@@ -23,12 +25,8 @@ type Version struct {
// (Note: cannot use time.Duration because marshalling with json breaks it)
CheckPeriod
string
// AutoUpdate is optional and has these these options:
// - "never" do not auto-update
// - "patch" auto-update on new patch versions
// - "minor" auto-update on new minor (or patch) versions (Default)
// - "major" auto-update on any new version
AutoUpdate
string
// AutoUpdate is optional
AutoUpdate
AutoUpdateSetting
}
// supported Version.Check values
...
...
@@ -43,13 +41,62 @@ const (
CheckIgnore
=
"ignore"
)
// supported Version.AutoUpdate values
// BUG(cryptix): make this a custom type that implements json.Unmarshaller() to verify values
// AutoUpdateSetting implements json.Unmarshaler to check values in config
// supported values:
// "never" - do not auto-update
// "patch" - auto-update on new patch versions
// "minor" - auto-update on new minor (or patch) versions (Default)
// "major" - auto-update on any new version
type
AutoUpdateSetting
int
// UnmarshalJSON checks the input against known strings
func
(
s
*
AutoUpdateSetting
)
UnmarshalJSON
(
in
[]
byte
)
error
{
switch
strings
.
ToLower
(
string
(
in
))
{
case
`"never"`
:
*
s
=
UpdateNever
case
`"major"`
:
*
s
=
UpdateMajor
case
`"minor"`
:
*
s
=
UpdateMinor
case
`"patch"`
:
*
s
=
UpdatePatch
default
:
*
s
=
UpdateMinor
return
ErrUnknownAutoUpdateSetting
}
return
nil
}
// MarshalJSON converts the value back to JSON string
func
(
s
AutoUpdateSetting
)
MarshalJSON
()
([]
byte
,
error
)
{
return
[]
byte
(
`"`
+
s
.
String
()
+
`"`
),
nil
}
// String converts valye to human readable string
func
(
s
AutoUpdateSetting
)
String
()
string
{
switch
s
{
case
UpdateNever
:
return
"never"
case
UpdateMajor
:
return
"major"
case
UpdateMinor
:
return
"minor"
case
UpdatePatch
:
return
"patch"
default
:
return
ErrUnknownAutoUpdateSetting
.
Error
()
}
}
// ErrUnknownAutoUpdateSetting is returned when an unknown value is read from the config
var
ErrUnknownAutoUpdateSetting
=
errors
.
New
(
"unknown value for AutoUpdate"
)
const
(
Update
Never
=
"never"
UpdatePatch
=
"patch"
UpdateM
inor
=
"minor"
Update
Major
=
"major"
Update
Minor
AutoUpdateSetting
=
iota
// first value so that it is the zero value and thus the default
UpdatePatch
UpdateM
ajor
Update
Never
)
// defaultCheckPeriod governs h
...
...
config/version_test.go
0 → 100644
浏览文件 @
24e1e6d1
package
config
import
(
"strings"
"testing"
)
func
TestAutoUpdateValues
(
t
*
testing
.
T
)
{
var
tval
struct
{
AutoUpdate
AutoUpdateSetting
}
tests
:=
[]
struct
{
input
string
val
AutoUpdateSetting
err
error
}{
{
`{"hello":123}`
,
UpdateMinor
,
nil
},
// default
{
`{"AutoUpdate": "never"}`
,
UpdateNever
,
nil
},
{
`{"AutoUpdate": "patch"}`
,
UpdatePatch
,
nil
},
{
`{"AutoUpdate": "minor"}`
,
UpdateMinor
,
nil
},
{
`{"AutoUpdate": "major"}`
,
UpdateMajor
,
nil
},
{
`{"AutoUpdate": "blarg"}`
,
UpdateMinor
,
ErrUnknownAutoUpdateSetting
},
}
for
i
,
tc
:=
range
tests
{
err
:=
Decode
(
strings
.
NewReader
(
tc
.
input
),
&
tval
)
if
err
!=
tc
.
err
{
t
.
Fatalf
(
"%d failed - got err %q wanted %v"
,
i
,
err
,
tc
.
err
)
}
if
tval
.
AutoUpdate
!=
tc
.
val
{
t
.
Fatalf
(
"%d failed - got val %q where we wanted %q"
,
i
,
tval
.
AutoUpdate
,
tc
.
val
)
}
}
}
updates/updates.go
浏览文件 @
24e1e6d1
...
...
@@ -64,7 +64,7 @@ func AbleToApply() error {
// ShouldAutoUpdate decides wether a new version should be applied
// checks against config setting and new version string. returns false in case of error
func
ShouldAutoUpdate
(
setting
,
newVer
string
)
bool
{
func
ShouldAutoUpdate
(
setting
config
.
AutoUpdateSetting
,
newVer
string
)
bool
{
if
setting
==
config
.
UpdateNever
{
return
false
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论