comparison pkg/xlsx/templater.go @ 5712:6270951dda28 revive-cleanup

/interface{}/any/
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 20 Feb 2024 22:37:51 +0100
parents 1222b777f51f
children
comparison
equal deleted inserted replaced
5711:2dd155cc95ec 5712:6270951dda28
198 198
199 func (e *executor) pushVars(vars []string) { 199 func (e *executor) pushVars(vars []string) {
200 e.frames = append(e.frames, frame{ 200 e.frames = append(e.frames, frame{
201 res: &sqlResult{ 201 res: &sqlResult{
202 columns: vars, 202 columns: vars,
203 rows: [][]interface{}{make([]interface{}, len(vars))}, 203 rows: [][]any{make([]any, len(vars))},
204 }, 204 },
205 }) 205 })
206 } 206 }
207 207
208 func (e *executor) popFrame() { 208 func (e *executor) popFrame() {
417 } 417 }
418 418
419 func (e *executor) sel(action *Action) error { 419 func (e *executor) sel(action *Action) error {
420 vars := e.vars() 420 vars := e.vars()
421 421
422 eval := func(x string) (interface{}, error) { 422 eval := func(x string) (any, error) {
423 f, err := e.expr(x) 423 f, err := e.expr(x)
424 if err != nil { 424 if err != nil {
425 return nil, err 425 return nil, err
426 } 426 }
427 return f(e.ctx, vars) 427 return f(e.ctx, vars)
516 } 516 }
517 517
518 return nil 518 return nil
519 } 519 }
520 520
521 func columnToNum(col interface{}) interface{} { 521 func columnToNum(col any) any {
522 var name string 522 var name string
523 switch v := col.(type) { 523 switch v := col.(type) {
524 case string: 524 case string:
525 name = v 525 name = v
526 default: 526 default:
532 return 1 532 return 1
533 } 533 }
534 return num 534 return num
535 } 535 }
536 536
537 func asInt(i interface{}) (int, error) { 537 func asInt(i any) (int, error) {
538 switch v := i.(type) { 538 switch v := i.(type) {
539 case int: 539 case int:
540 return v, nil 540 return v, nil
541 case int8: 541 case int8:
542 return int(v), nil 542 return int(v), nil
555 default: 555 default:
556 return 0, fmt.Errorf("invalid int '%v'", i) 556 return 0, fmt.Errorf("invalid int '%v'", i)
557 } 557 }
558 } 558 }
559 559
560 func coord2cell(ix, iy interface{}) interface{} { 560 func coord2cell(ix, iy any) any {
561 x, err := asInt(ix) 561 x, err := asInt(ix)
562 if err != nil { 562 if err != nil {
563 log.Errorf("invalid x value: %v\n", err) 563 log.Errorf("invalid x value: %v\n", err)
564 return "A1" 564 return "A1"
565 } 565 }
592 } 592 }
593 e.expressions[x] = f 593 e.expressions[x] = f
594 return f, nil 594 return f, nil
595 } 595 }
596 596
597 func (e *executor) vars() map[string]interface{} { 597 func (e *executor) vars() map[string]any {
598 vars := map[string]interface{}{} 598 vars := map[string]any{}
599 if len(e.frames) > 0 { 599 if len(e.frames) > 0 {
600 vars["row_number"] = e.frames[len(e.frames)-1].index 600 vars["row_number"] = e.frames[len(e.frames)-1].index
601 } 601 }
602 for i := len(e.frames) - 1; i >= 0; i-- { 602 for i := len(e.frames) - 1; i >= 0; i-- {
603 fr := &e.frames[i] 603 fr := &e.frames[i]
610 return vars 610 return vars
611 } 611 }
612 612
613 func (e *executor) expand( 613 func (e *executor) expand(
614 str string, 614 str string,
615 vars map[string]interface{}, 615 vars map[string]any,
616 ) (string, error) { 616 ) (string, error) {
617 617
618 var err error 618 var err error
619 619
620 replace := func(s string) string { 620 replace := func(s string) string {
636 return str, err 636 return str, err
637 } 637 }
638 638
639 func (e *executor) typedExpand( 639 func (e *executor) typedExpand(
640 str string, 640 str string,
641 vars map[string]interface{}, 641 vars map[string]any,
642 ) (interface{}, error) { 642 ) (any, error) {
643 643
644 var ( 644 var (
645 err error 645 err error
646 repCount int 646 repCount int
647 last interface{} 647 last any
648 ) 648 )
649 649
650 replace := func(s string) string { 650 replace := func(s string) string {
651 if err != nil { 651 if err != nil {
652 return "" 652 return ""