Source File
reflect.go
Belonging Package
golang.org/x/pkgsite/internal/database
package database
import (
)
func ( interface{}) func( interface{}) []interface{} {
:= reflect.ValueOf()
if .Kind() == reflect.Ptr {
= .Elem()
}
return structScannerForType(.Type())
}
type fieldInfo struct {
num int // to pass to v.Field
kind reflect.Kind
}
func ( reflect.Type) func( interface{}) []interface{} {
if .Kind() != reflect.Struct {
panic(fmt.Sprintf("%s is not a struct", ))
}
:= .ptr.Elem().Type() // T
if == nil {
.ptr.Elem().Set(reflect.Zero()) // *v = nil
} else {
:= reflect.New(.Elem()) // p := new(T)
.Elem().Set(reflect.ValueOf()) // *p = value
.ptr.Elem().Set() // *v = p
}
return nil
}
func ( nullPtr) () (driver.Value, error) {
if .ptr.Elem().IsNil() {
return nil, nil
}
return .ptr.Elem().Elem().Interface(), nil
}
func ( *DB) ( context.Context, interface{}, string, ...interface{}) error {
:= reflect.ValueOf()
if .Kind() != reflect.Ptr {
return errors.New("collectStructs: arg is not a pointer")
}
:= .Elem()
if .Kind() != reflect.Slice {
return errors.New("collectStructs: arg is not a pointer to a slice")
}
:= false
:= .Type().Elem() // slice element type
if .Kind() == reflect.Ptr {
= true
= .Elem()
}
if .Kind() != reflect.Struct {
return fmt.Errorf("slice element type is neither struct nor struct pointer: %s", .Type().Elem())
}
:= structScannerForType()
:= .RunQuery(, , func( *sql.Rows) error {
:= reflect.New()
if := .Scan((.Interface())...); != nil {
return
}
if ! {
= .Elem()
}
= reflect.Append(, )
return nil
}, ...)
if != nil {
return
}
.Elem().Set()
return nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |