parent
4d42ed5798
commit
225ad90bdb
@ -0,0 +1,44 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name err_field.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
type (
|
||||
|
||||
// ErrField no puede heredar directamente de Errs.Code
|
||||
// ya que es utilizada por dependencias usadas por Errs
|
||||
//
|
||||
ErrField string
|
||||
)
|
||||
|
||||
|
||||
func (e ErrField) Error() string {
|
||||
return string(e) }
|
||||
|
||||
|
||||
func (e ErrField) Code () string {
|
||||
return string(e) }
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,74 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
partSField struct {
|
||||
name string
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func makePartSField(name string) partSField {
|
||||
//checkFieldName(name)
|
||||
return partSField{ name: name }
|
||||
}
|
||||
|
||||
func (f partSField) Name () string {
|
||||
return f.name }
|
||||
|
||||
|
||||
|
||||
func (f partSField) Bool () (bool,bool) {
|
||||
return false,false }
|
||||
|
||||
func (f partSField) String () (string,bool) {
|
||||
return "",false }
|
||||
|
||||
func (f partSField) Signed () (int,bool) {
|
||||
return 0,false }
|
||||
|
||||
func (f partSField) Unsigned () (uint,bool) {
|
||||
return 0,false }
|
||||
|
||||
func (f partSField) Date () (time.Time,bool) {
|
||||
return *new(time.Time),false }
|
||||
|
||||
func (f partSField) Time () (time.Time,bool) {
|
||||
return *new(time.Time),false }
|
||||
|
||||
func (f partSField) Error () (error,bool) {
|
||||
return nil,false }
|
||||
|
||||
func (f partSField) Binary () ([]byte,bool) {
|
||||
return nil,false }
|
||||
|
||||
func (f partSField) Reflect() (reflect.Value,bool) {
|
||||
return *new(reflect.Value),false }
|
||||
@ -0,0 +1,56 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
SField interface {
|
||||
Name () string
|
||||
Kind () Kind
|
||||
|
||||
Value() any
|
||||
|
||||
Any () (any,bool)
|
||||
Bool () (bool,bool)
|
||||
String () (string,bool)
|
||||
Signed () (int,bool)
|
||||
Unsigned () (uint,bool)
|
||||
Date () (time.Time,bool)
|
||||
Time () (time.Time,bool)
|
||||
Error () (error,bool)
|
||||
Binary () ([]byte,bool)
|
||||
Reflect () (reflect.Value,bool)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,139 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield_any.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
SFieldAny struct {
|
||||
partSField
|
||||
value any
|
||||
}
|
||||
)
|
||||
|
||||
func NewSFieldAny (name string, value any) *SFieldAny {
|
||||
return &SFieldAny{
|
||||
partSField: makePartSField(name),
|
||||
value : value } }
|
||||
|
||||
|
||||
|
||||
func (_ SFieldAny) Kind () Kind {
|
||||
return KindAny }
|
||||
|
||||
func (f SFieldAny) Value() any {
|
||||
return f.value }
|
||||
|
||||
func (f SFieldAny) Any () (any,bool) {
|
||||
return f.value,true }
|
||||
|
||||
|
||||
func (f SFieldAny) Bool () (bool,bool) {
|
||||
v,ok := f.value.(bool)
|
||||
return v,ok
|
||||
}
|
||||
|
||||
|
||||
func (f SFieldAny) String () (string,bool) {
|
||||
v,ok := f.value.(string)
|
||||
return v,ok
|
||||
}
|
||||
|
||||
func (f SFieldAny) Signed () (int,bool) {
|
||||
switch t := f.value.(type) {
|
||||
case int : return t,true
|
||||
case int8 : return int(t),true
|
||||
case int16: return int(t),true
|
||||
case int32: return int(t),true
|
||||
case int64: return int(t),true
|
||||
default : return 0,false
|
||||
}
|
||||
}
|
||||
|
||||
func (f SFieldAny) Unsigned () (uint,bool) {
|
||||
switch t := f.value.(type) {
|
||||
case uint : return t,true
|
||||
case uint8 : return uint(t),true
|
||||
case uint16: return uint(t),true
|
||||
case uint32: return uint(t),true
|
||||
case uint64: return uint(t),true
|
||||
default : return 0,false
|
||||
}
|
||||
}
|
||||
|
||||
func (f SFieldAny) Float () (float64,bool) {
|
||||
v, ok := f.value.(float64)
|
||||
if !ok {
|
||||
var f32 float32
|
||||
if f32,ok = f.value.(float32); ok {
|
||||
v = float64(f32)
|
||||
}
|
||||
}
|
||||
return v, ok
|
||||
}
|
||||
|
||||
|
||||
func (f SFieldAny) Date () (time.Time,bool) {
|
||||
v, ok := f.value.(time.Time)
|
||||
return v, ok
|
||||
}
|
||||
|
||||
func (f SFieldAny) Time () (time.Time,bool) {
|
||||
v, ok := f.value.(time.Time)
|
||||
return v, ok
|
||||
}
|
||||
|
||||
func (f SFieldAny) Error () (error,bool) {
|
||||
v, ok := f.value.(error)
|
||||
return v, ok
|
||||
}
|
||||
|
||||
func (f SFieldAny) Binary () ([]byte,bool) {
|
||||
v, ok := f.value.([]byte)
|
||||
return v, ok
|
||||
}
|
||||
|
||||
|
||||
func (f SFieldAny) Reflect () (reflect.Value,bool) {
|
||||
v, ok := f.value.(reflect.Value)
|
||||
return v, ok
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield_bool.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
SFieldBool struct {
|
||||
partSField
|
||||
value bool
|
||||
}
|
||||
)
|
||||
|
||||
func NewSFieldBool (name string, value bool) *SFieldBool {
|
||||
return &SFieldBool{
|
||||
partSField: makePartSField(name),
|
||||
value: value } }
|
||||
|
||||
|
||||
|
||||
func (_ SFieldBool) Kind () Kind {
|
||||
return KindSigned }
|
||||
|
||||
func (f SFieldBool) Value() any {
|
||||
return f.value }
|
||||
|
||||
|
||||
func (f SFieldBool) Any () (any,bool) {
|
||||
return f.value,true }
|
||||
|
||||
func (f SFieldBool) Bool() (bool,bool) {
|
||||
return f.value,true }
|
||||
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield_error.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
SFieldError struct {
|
||||
partSField
|
||||
value error
|
||||
}
|
||||
)
|
||||
|
||||
func NewSFieldError(name string, value error) *SFieldError {
|
||||
return &SFieldError{
|
||||
partSField: makePartSField(name),
|
||||
value: value } }
|
||||
|
||||
|
||||
|
||||
func (_ SFieldError) Kind () Kind {
|
||||
return KindError }
|
||||
|
||||
func (f SFieldError) Value() any {
|
||||
return f.value }
|
||||
|
||||
|
||||
func (f SFieldError) Any () (any,bool) {
|
||||
return f.value,true }
|
||||
|
||||
func (f SFieldError) Error() (error,bool) {
|
||||
return f.value,true }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield_float.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
SFieldFloat struct {
|
||||
partSField
|
||||
value float64
|
||||
}
|
||||
)
|
||||
|
||||
func NewSFieldFloat(name string, value float64) *SFieldFloat {
|
||||
return &SFieldFloat{
|
||||
partSField: makePartSField(name),
|
||||
value: value } }
|
||||
|
||||
|
||||
|
||||
func (_ SFieldFloat) Kind () Kind {
|
||||
return KindFloat }
|
||||
|
||||
func (f SFieldFloat) Value() any {
|
||||
return f.value }
|
||||
|
||||
|
||||
func (f SFieldFloat) Any () (any,bool) {
|
||||
return f.value,true }
|
||||
|
||||
func (f SFieldFloat) Float() (float64,bool) {
|
||||
return f.value,true }
|
||||
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield_reflect.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
import "reflect"
|
||||
|
||||
type (
|
||||
|
||||
SFieldReflect struct {
|
||||
partSField
|
||||
value reflect.Value
|
||||
}
|
||||
)
|
||||
|
||||
func NewSFieldReflect(name string, value reflect.Value) *SFieldReflect {
|
||||
return &SFieldReflect{
|
||||
partSField: makePartSField(name),
|
||||
value: value } }
|
||||
|
||||
|
||||
|
||||
func (_ SFieldReflect) Kind () Kind {
|
||||
return KindReflect }
|
||||
|
||||
func (f SFieldReflect) Value() any {
|
||||
return f.value }
|
||||
|
||||
|
||||
func (f SFieldReflect) Any () (any,bool) {
|
||||
return f.value,true }
|
||||
|
||||
func (f SFieldReflect) Reflect() (reflect.Value,bool) {
|
||||
return f.value,true }
|
||||
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield_signed.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
SFieldSigned struct {
|
||||
partSField
|
||||
value int
|
||||
}
|
||||
)
|
||||
|
||||
func NewSFieldSigned (name string, value int) *SFieldSigned {
|
||||
return &SFieldSigned{
|
||||
partSField: makePartSField(name),
|
||||
value: value } }
|
||||
|
||||
|
||||
|
||||
func (_ SFieldSigned) Kind () Kind {
|
||||
return KindSigned }
|
||||
|
||||
func (f SFieldSigned) Value() any {
|
||||
return f.value }
|
||||
|
||||
|
||||
func (f SFieldSigned) Any () (any,bool) {
|
||||
return f.value,true }
|
||||
|
||||
func (f SFieldSigned) Signed() (int,bool) {
|
||||
return f.value,true }
|
||||
@ -0,0 +1,54 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield_string.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
SFieldString struct {
|
||||
partSField
|
||||
value string
|
||||
}
|
||||
)
|
||||
|
||||
func NewSFieldString (name string, value string) *SFieldString {
|
||||
return &SFieldString{
|
||||
partSField: makePartSField(name),
|
||||
value : value } }
|
||||
|
||||
|
||||
|
||||
func (_ SFieldString) Kind () Kind {
|
||||
return KindString }
|
||||
|
||||
func (f SFieldString) Value() any {
|
||||
return f.value }
|
||||
|
||||
|
||||
func (f SFieldString) Any () (any,bool) {
|
||||
return f.value,true }
|
||||
|
||||
func (f SFieldString) String() (string,bool) {
|
||||
return f.value,true }
|
||||
@ -0,0 +1,54 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfield_unsigned.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
|
||||
type (
|
||||
|
||||
SFieldUnsigned struct {
|
||||
partSField
|
||||
value uint
|
||||
}
|
||||
)
|
||||
|
||||
func NewSFieldUnsigned(name string, value uint) *SFieldUnsigned {
|
||||
return &SFieldUnsigned{
|
||||
partSField: makePartSField(name),
|
||||
value : value } }
|
||||
|
||||
|
||||
func (_ SFieldUnsigned) Kind () Kind {
|
||||
return KindUnsigned }
|
||||
|
||||
func (f SFieldUnsigned) Value() any {
|
||||
return f.value }
|
||||
|
||||
|
||||
func (f SFieldUnsigned) Any () (any,bool) {
|
||||
return f.value,true }
|
||||
|
||||
func (f SFieldUnsigned) Unsigned() (uint,bool) {
|
||||
return f.value,true }
|
||||
|
||||
|
||||
@ -0,0 +1,89 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name sfields.go
|
||||
// Created by DEV
|
||||
// Modified 30/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package flds
|
||||
|
||||
import "sort"
|
||||
|
||||
type (
|
||||
|
||||
SFields []SField
|
||||
|
||||
)
|
||||
|
||||
|
||||
func (f SFields) Len () int {
|
||||
return len(f) }
|
||||
|
||||
func (f SFields) Has (name string) bool {
|
||||
return f.has(name) != -1 }
|
||||
|
||||
func (f SFields) has (name string) int {
|
||||
for i,f := range f {
|
||||
if f.Name() == name {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (f SFields) Kinds() Kind {
|
||||
var k Kind
|
||||
for _,f := range f {
|
||||
k|=f.Kind()
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
func (f SFields) GeField (name string) SField {
|
||||
if p := f.has(name); p != -1 {
|
||||
return f[p]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f SFields) AddField (field SField) SFields {
|
||||
if field != nil {
|
||||
return append(f,field)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func (f SFields) DelField (name string) SFields {
|
||||
if p := f.has(name); p != -1 {
|
||||
return append(f[:p],f[p+1:]...)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (f SFields) Sort() {
|
||||
sort.Sort(f) }
|
||||
|
||||
func (f SFields) Swap(i, j int) {
|
||||
f[i], f[j] = f[j], f[i] }
|
||||
|
||||
func (f SFields) Less(i, j int) bool {
|
||||
return f[i].Name() < f[j].Name() }
|
||||
|
||||
Loading…
Reference in new issue