Update interface{} -> any

This commit is contained in:
Fedor Korotkiy 2023-02-25 13:05:00 +04:00
parent 46e4498e1c
commit b5cdde807d

View file

@ -171,13 +171,13 @@ Methods
* Interfaces * Interfaces
func Fprintf(w io.Writer, format string, args ...interface{}) (int, error) func Fprintf(w io.Writer, format string, args ...any) (int, error)
func Printf(format string, args ...interface{}) (int, error) { func Printf(format string, args ...any) (int, error) {
return Fprintf(os.Stdout, format, args...) return Fprintf(os.Stdout, format, args...)
} }
func Sprintf(format string, args ...interface{}) string { func Sprintf(format string, args ...any) string {
var buf bytes.Buffer var buf bytes.Buffer
Fprintf(&buf, format, args...) Fprintf(&buf, format, args...)
return buf.String() return buf.String()
@ -262,14 +262,18 @@ Methods
var _ fmt.Stringer = &s // OK var _ fmt.Stringer = &s // OK
var _ fmt.Stringer = s // compile error: IntSet lacks String method var _ fmt.Stringer = s // compile error: IntSet lacks String method
* interface{} * any
var any interface{} type any = interface{}
any = true
any = 12.34 - `any` - это alias для `interface{}`
any = "hello"
any = map[string]int{"one": 1} var v any
any = new(bytes.Buffer) v = true
v = 12.34
v = "hello"
v = map[string]int{"one": 1}
v = new(bytes.Buffer)
* Interface satisfaction * Interface satisfaction
@ -283,7 +287,7 @@ Methods
w = new(bytes.Buffer) w = new(bytes.Buffer)
w = nil w = nil
var x interface{} = time.Now() var x any = time.Now()
* Nil pointer * Nil pointer
@ -342,7 +346,7 @@ Check type
* Type switches * Type switches
func sqlQuote(x interface{}) string { func sqlQuote(x any) string {
if x == nil { if x == nil {
return "NULL" return "NULL"
} else if _, ok := x.(int); ok { } else if _, ok := x.(int); ok {
@ -375,12 +379,12 @@ Check type
* Type switch * Type switch
func sqlQuote(x interface{}) string { func sqlQuote(x any) string {
switch v := x.(type) { switch v := x.(type) {
case nil: case nil:
return "NULL" return "NULL"
case int, uint: case int, uint:
return fmt.Sprintf("%d", v) // v has type interface{} here. return fmt.Sprintf("%d", v) // v has type any here.
case bool: case bool:
if v { if v {
return "TRUE" return "TRUE"