crypto/sha256: Sum256 and Sum224 functions to simplify hashing (CL 10629043).
crypto/sha512: Sum512 and Sum384 functions to simplify hashing (CL 10630043).
crypto/tls: add support for TLS 1.1. (CL 7872043).
+flag: add Getter interface (CL 10472043).
fmt: indexed access to arguments in Printf etc. (CL 9680043).
go/build: support including C++ code with cgo (CL 8248043).
io: Copy prioritizes WriterTo over ReaderFrom (CL 9462044).
return err
}
+func (b *boolValue) Get() interface{} { return bool(*b) }
+
func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
func (b *boolValue) IsBoolFlag() bool { return true }
return err
}
+func (i *intValue) Get() interface{} { return int(*i) }
+
func (i *intValue) String() string { return fmt.Sprintf("%v", *i) }
// -- int64 Value
return err
}
+func (i *int64Value) Get() interface{} { return int64(*i) }
+
func (i *int64Value) String() string { return fmt.Sprintf("%v", *i) }
// -- uint Value
return err
}
+func (i *uintValue) Get() interface{} { return uint(*i) }
+
func (i *uintValue) String() string { return fmt.Sprintf("%v", *i) }
// -- uint64 Value
return err
}
+func (i *uint64Value) Get() interface{} { return uint64(*i) }
+
func (i *uint64Value) String() string { return fmt.Sprintf("%v", *i) }
// -- string Value
return nil
}
+func (s *stringValue) Get() interface{} { return string(*s) }
+
func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
// -- float64 Value
return err
}
+func (f *float64Value) Get() interface{} { return float64(*f) }
+
func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) }
// -- time.Duration Value
return err
}
+func (d *durationValue) Get() interface{} { return time.Duration(*d) }
+
func (d *durationValue) String() string { return (*time.Duration)(d).String() }
// Value is the interface to the dynamic value stored in a flag.
Set(string) error
}
+// Getter is an interface that allows the contents of a Value to be retrieved.
+// It wraps the Value interface, rather than being part of it, because it
+// appeared after Go 1 and its compatibility rules. All Value types provided
+// by this package satisfy the Getter interface.
+type Getter interface {
+ Value
+ Get() interface{}
+}
+
// ErrorHandling defines how to handle flag parsing errors.
type ErrorHandling int
}
}
+func TestGet(t *testing.T) {
+ ResetForTesting(nil)
+ Bool("test_bool", true, "bool value")
+ Int("test_int", 1, "int value")
+ Int64("test_int64", 2, "int64 value")
+ Uint("test_uint", 3, "uint value")
+ Uint64("test_uint64", 4, "uint64 value")
+ String("test_string", "5", "string value")
+ Float64("test_float64", 6, "float64 value")
+ Duration("test_duration", 7, "time.Duration value")
+
+ visitor := func(f *Flag) {
+ if len(f.Name) > 5 && f.Name[0:5] == "test_" {
+ g, ok := f.Value.(Getter)
+ if !ok {
+ t.Errorf("Visit: value does not satisfy Getter: %T", f.Value)
+ return
+ }
+ switch f.Name {
+ case "test_bool":
+ ok = g.Get() == true
+ case "test_int":
+ ok = g.Get() == int(1)
+ case "test_int64":
+ ok = g.Get() == int64(2)
+ case "test_uint":
+ ok = g.Get() == uint(3)
+ case "test_uint64":
+ ok = g.Get() == uint64(4)
+ case "test_string":
+ ok = g.Get() == "5"
+ case "test_float64":
+ ok = g.Get() == float64(6)
+ case "test_duration":
+ ok = g.Get() == time.Duration(7)
+ }
+ if !ok {
+ t.Errorf("Visit: bad value %T(%v) for %s", g.Get(), g.Get(), f.Name)
+ }
+ }
+ }
+ VisitAll(visitor)
+}
+
func TestUsage(t *testing.T) {
called := false
ResetForTesting(func() { called = true })