package ultraviolet import ( "fmt" "reflect" ) type SQ struct { value reflect.Value } func NewSQ(value any) *SQ { return &SQ{ value: reflect.ValueOf(value).Elem(), } } func newSQInternal(value reflect.Value) *SQ { return &SQ{ value: value, } } func (this *SQ) Field(name string) *SQ { if this.value.Kind() != reflect.Struct { return nil } return newSQInternal( this.value.FieldByName(name), ) } func (this *SQ) Length() int { return this.value.Len() } func (this *SQ) Index(index int) *SQ { if this.value.Kind() != reflect.Slice { return nil } return newSQInternal( this.value.Index(index), ) } func (this *SQ) Keys() []string { result := []string{} for _, key := range this.value.MapKeys() { result = append(result, key.String()) } return result } func (this *SQ) Key(key string) *SQ { if this.value.Kind() != reflect.Map { return nil } return newSQInternal( this.value.MapIndex(reflect.ValueOf(key)), ) } func (this *SQ) Value() any { if this.value.Kind() == reflect.Int { return fmt.Sprintf("%d", this.value.Int()) } return this.value.String() } func (this *SQ) ValueInt() any { return this.value.Int() } func (this *SQ) ValueString() any { return this.value.String() }