// ------------------------------------------------------------------------ // â„šī¸ Project active3 // Active Thing (activething.com) git.activething.com/go // // File name field.go // âœī¸ Created by DEV // 📅 Modified 01/05/2024 // // 🔒 COPYRIGHT 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 acache import "ablds" type ( Field interface { NativeResolver Kind () Kind Name () string Value() any } ) func FieldAsBuildable (field Field) ablds.BuildFnc { return func (b ablds.Builder) { buildFieldAsObject(field,b) } } func buildFieldAsObject (field Field, builder ablds.Builder) { builder.Object(func(ob ablds.ObjectBuilder){ buildFieldAsField(field,ob) }) } func buildFieldAsField (field Field, obuilder ablds.ObjectBuilder) { vb := obuilder.Field(field.Name()) switch field.Kind() { case KindAny : vb.Any (field.Value()) case KindBool : v,_ := field.Bool(); vb.Bool(v) case KindBinary : v,_ := field.Binary(); vb.Binary(v) case KindString : v,_ := field.String(); vb.String(v) case KindInt : v,_ := field.Int(); vb.Int(v) case KindUint : v,_ := field.Uint(); vb.Uint(v) case KindFloat : v,_ := field.Float(); vb.Float64(v) case KindTime : v,_ := field.Time(); vb.Time(v) case KindDuration: v,_ := field.Duration(); vb.Duration(v) case KindError : v,_ := field.Error(); vb.Error(v) case KindReflect : v,_ := field.Reflect(); vb.Reflect(v) default: vb.Any(field.Value()) } }