本文整理汇总了Golang中github.com/timeglass/glass/_vendor/golang.org/x/sys/windows/registry.Key.GetValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Key.GetValue方法的具体用法?Golang Key.GetValue怎么用?Golang Key.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/timeglass/glass/_vendor/golang.org/x/sys/windows/registry.Key
的用法示例。
在下文中一共展示了Key.GetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: walkKey
func walkKey(t *testing.T, k registry.Key, kname string) {
names, err := k.ReadValueNames(-1)
if err != nil {
t.Fatalf("reading value names of %s failed: %v", kname, err)
}
for _, name := range names {
_, valtype, err := k.GetValue(name, nil)
if err != nil {
t.Fatalf("reading value type of %s of %s failed: %v", name, kname, err)
}
switch valtype {
case registry.NONE:
case registry.SZ:
_, _, err := k.GetStringValue(name)
if err != nil {
t.Error(err)
}
case registry.EXPAND_SZ:
s, _, err := k.GetStringValue(name)
if err != nil {
t.Error(err)
}
_, err = registry.ExpandString(s)
if err != nil {
t.Error(err)
}
case registry.DWORD, registry.QWORD:
_, _, err := k.GetIntegerValue(name)
if err != nil {
t.Error(err)
}
case registry.BINARY:
_, _, err := k.GetBinaryValue(name)
if err != nil {
t.Error(err)
}
case registry.MULTI_SZ:
_, _, err := k.GetStringsValue(name)
if err != nil {
t.Error(err)
}
case registry.FULL_RESOURCE_DESCRIPTOR, registry.RESOURCE_LIST, registry.RESOURCE_REQUIREMENTS_LIST:
// TODO: not implemented
default:
t.Fatalf("value type %d of %s of %s failed: %v", valtype, name, kname, err)
}
}
names, err = k.ReadSubKeyNames(-1)
if err != nil {
t.Fatalf("reading sub-keys of %s failed: %v", kname, err)
}
for _, name := range names {
func() {
subk, err := registry.OpenKey(k, name, registry.ENUMERATE_SUB_KEYS|registry.QUERY_VALUE)
if err != nil {
if err == syscall.ERROR_ACCESS_DENIED {
// ignore error, if we are not allowed to access this key
return
}
t.Fatalf("opening sub-keys %s of %s failed: %v", name, kname, err)
}
defer subk.Close()
walkKey(t, subk, kname+`\`+name)
}()
}
}
示例2: testGetValue
func testGetValue(t *testing.T, k registry.Key, test ValueTest, size int) {
if size <= 0 {
return
}
// read data with no buffer
gotsize, gottype, err := k.GetValue(test.Name, nil)
if err != nil {
t.Errorf("GetValue(%s, [%d]byte) failed: %v", test.Name, size, err)
return
}
if gotsize != size {
t.Errorf("want %s value size of %d, got %v", test.Name, size, gotsize)
return
}
if gottype != test.Type {
t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
return
}
// read data with short buffer
gotsize, gottype, err = k.GetValue(test.Name, make([]byte, size-1))
if err == nil {
t.Errorf("GetValue(%s, [%d]byte) should fail, but suceeded", test.Name, size-1)
return
}
if err != registry.ErrShortBuffer {
t.Errorf("reading %s value should return 'short buffer' error, but got: %s", test.Name, err)
return
}
if gotsize != size {
t.Errorf("want %s value size of %d, got %v", test.Name, size, gotsize)
return
}
if gottype != test.Type {
t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
return
}
// read full data
gotsize, gottype, err = k.GetValue(test.Name, make([]byte, size))
if err != nil {
t.Errorf("GetValue(%s, [%d]byte) failed: %v", test.Name, size, err)
return
}
if gotsize != size {
t.Errorf("want %s value size of %d, got %v", test.Name, size, gotsize)
return
}
if gottype != test.Type {
t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
return
}
// check GetValue returns ErrNotExist as required
_, _, err = k.GetValue(test.Name+"_not_there", make([]byte, size))
if err == nil {
t.Errorf("GetValue(%q) should not succeed", test.Name)
return
}
if err != registry.ErrNotExist {
t.Errorf("GetValue(%q) should return 'not exist' error, but got: %s", test.Name, err)
return
}
}