Source File
aclitem_array.go
Belonging Package
github.com/jackc/pgtype
package pgtype
import (
)
type ACLItemArray struct {
Elements []ACLItem
Dimensions []ArrayDimension
Status Status
}
if == nil {
* = ACLItemArray{Status: Null}
return nil
}
if , := .(interface{ () interface{} }); {
:= .()
if != {
return .()
}
}
switch value := .(type) {
case []string:
if == nil {
* = ACLItemArray{Status: Null}
} else if len() == 0 {
* = ACLItemArray{Status: Present}
} else {
:= make([]ACLItem, len())
for := range {
if := [].Set([]); != nil {
return
}
}
* = ACLItemArray{
Elements: ,
Dimensions: []ArrayDimension{{Length: int32(len()), LowerBound: 1}},
Status: Present,
}
}
case []*string:
if == nil {
* = ACLItemArray{Status: Null}
} else if len() == 0 {
* = ACLItemArray{Status: Present}
} else {
:= make([]ACLItem, len())
for := range {
if := [].Set([]); != nil {
return
}
}
* = ACLItemArray{
Elements: ,
Dimensions: []ArrayDimension{{Length: int32(len()), LowerBound: 1}},
Status: Present,
}
}
case []ACLItem:
if == nil {
* = ACLItemArray{Status: Null}
} else if len() == 0 {
* = ACLItemArray{Status: Present}
} else {
* = ACLItemArray{
Elements: ,
Dimensions: []ArrayDimension{{Length: int32(len()), LowerBound: 1}},
Status: Present,
}
}
:= reflect.ValueOf()
if !.IsValid() || .IsZero() {
* = ACLItemArray{Status: Null}
return nil
}
, , := findDimensionsFromValue(, nil, 0)
if ! {
return fmt.Errorf("cannot find dimensions of %v for ACLItemArray", )
}
if == 0 {
* = ACLItemArray{Status: Present}
return nil
}
if len() == 0 {
if , := underlyingSliceType(); {
return .()
}
return fmt.Errorf("cannot convert %v to ACLItemArray", )
}
* = ACLItemArray{
Elements: make([]ACLItem, ),
Dimensions: ,
Status: Present,
}
, := .setRecursive(, 0, 0)
if len(.Dimensions) > 1 {
.Dimensions = .Dimensions[:len(.Dimensions)-1]
= 0
for , := range .Dimensions {
if == 0 {
= int(.Length)
} else {
*= int(.Length)
}
}
.Elements = make([]ACLItem, )
, = .setRecursive(, 0, 0)
if != nil {
return
}
} else {
return
}
}
if != len(.Elements) {
return fmt.Errorf("cannot convert %v to ACLItemArray, expected %d dst.Elements, but got %d instead", , len(.Elements), )
}
}
return nil
}
func ( *ACLItemArray) ( reflect.Value, , int) (int, error) {
switch .Kind() {
case reflect.Array:
fallthrough
case reflect.Slice:
if len(.Dimensions) == {
break
}
:= .Len()
if int32() != .Dimensions[].Length {
return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions")
}
for := 0; < ; ++ {
var error
, = .(.Index(), , +1)
if != nil {
return 0,
}
}
return , nil
}
if !.CanInterface() {
return 0, fmt.Errorf("cannot convert all values to ACLItemArray")
}
if := .Elements[].Set(.Interface()); != nil {
return 0, fmt.Errorf("%v in ACLItemArray", )
}
++
return , nil
}
func ( ACLItemArray) () interface{} {
switch .Status {
case Present:
return
case Null:
return nil
default:
return .Status
}
}
func ( *ACLItemArray) ( interface{}) error {
switch .Status {
case Present:
switch v := .(type) {
case *[]string:
* = make([]string, len(.Elements))
for := range .Elements {
if := .Elements[].AssignTo(&((*)[])); != nil {
return
}
}
return nil
case *[]*string:
* = make([]*string, len(.Elements))
for := range .Elements {
if := .Elements[].AssignTo(&((*)[])); != nil {
return
}
}
return nil
}
}
if , := GetAssignToDstType(); {
return .()
}
:= reflect.ValueOf()
if .Kind() == reflect.Ptr {
= .Elem()
}
switch .Kind() {
case reflect.Array, reflect.Slice:
default:
return fmt.Errorf("cannot assign %T to %T", , )
}
if len(.Elements) == 0 {
if .Kind() == reflect.Slice {
.Set(reflect.MakeSlice(.Type(), 0, 0))
return nil
}
}
, := .assignToRecursive(, 0, 0)
if != nil {
return
}
if != len(.Elements) {
return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", , len(.Elements), )
}
return nil
case Null:
return NullAssignTo()
}
return fmt.Errorf("cannot decode %#v into %T", , )
}
func ( *ACLItemArray) ( reflect.Value, , int) (int, error) {
switch := .Kind(); {
case reflect.Array:
fallthrough
case reflect.Slice:
if len(.Dimensions) == {
break
}
:= int(.Dimensions[].Length)
if reflect.Array == {
:= .Type()
if .Len() != {
return 0, fmt.Errorf("expected size %d array, but %s has size %d array", , , .Len())
}
.Set(reflect.New().Elem())
} else {
.Set(reflect.MakeSlice(.Type(), , ))
}
var error
for := 0; < ; ++ {
, = .(.Index(), , +1)
if != nil {
return 0,
}
}
return , nil
}
if len(.Dimensions) != {
return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(.Dimensions), )
}
if !.CanAddr() {
return 0, fmt.Errorf("cannot assign all values from ACLItemArray")
}
:= .Addr()
if !.CanInterface() {
return 0, fmt.Errorf("cannot assign all values from ACLItemArray")
}
if := .Elements[].AssignTo(.Interface()); != nil {
return 0,
}
++
return , nil
}
func ( *ACLItemArray) ( *ConnInfo, []byte) error {
if == nil {
* = ACLItemArray{Status: Null}
return nil
}
, := ParseUntypedTextArray(string())
if != nil {
return
}
var []ACLItem
if len(.Elements) > 0 {
= make([]ACLItem, len(.Elements))
for , := range .Elements {
var ACLItem
var []byte
if != "NULL" || .Quoted[] {
= []byte()
}
= .DecodeText(, )
if != nil {
return
}
[] =
}
}
* = ACLItemArray{Elements: , Dimensions: .Dimensions, Status: Present}
return nil
}
func ( ACLItemArray) ( *ConnInfo, []byte) ([]byte, error) {
switch .Status {
case Null:
return nil, nil
case Undefined:
return nil, errUndefined
}
if len(.Dimensions) == 0 {
return append(, '{', '}'), nil
}
= EncodeTextArrayDimensions(, .Dimensions)
:= make([]int, len(.Dimensions))
[len(.Dimensions)-1] = int(.Dimensions[len(.Dimensions)-1].Length)
for := len(.Dimensions) - 2; > -1; -- {
[] = int(.Dimensions[].Length) * [+1]
}
:= make([]byte, 0, 32)
for , := range .Elements {
if > 0 {
= append(, ',')
}
for , := range {
if % == 0 {
= append(, '{')
}
}
, := .EncodeText(, )
if != nil {
return nil,
}
if == nil {
= append(, `NULL`...)
} else {
= append(, QuoteArrayElementIfNeeded(string())...)
}
for , := range {
if (+1)% == 0 {
= append(, '}')
}
}
}
return , nil
}
func ( *ACLItemArray) ( interface{}) error {
if == nil {
return .DecodeText(nil, nil)
}
switch src := .(type) {
case string:
return .DecodeText(nil, []byte())
case []byte:
:= make([]byte, len())
copy(, )
return .DecodeText(nil, )
}
return fmt.Errorf("cannot scan %T", )
}
![]() |
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. |