github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/types/querystring/index.go (about)

     1  package string
     2  
     3  import (
     4  	"github.com/lmorg/murex/lang"
     5  	"github.com/lmorg/murex/lang/stdio"
     6  	"github.com/lmorg/murex/lang/types"
     7  )
     8  
     9  func index(p *lang.Process, params []string) error {
    10  	match := make(map[string]bool)
    11  	for i := range params {
    12  		match[params[i]] = true
    13  	}
    14  
    15  	var (
    16  		v       interface{}
    17  		typeErr error
    18  	)
    19  
    20  	err := p.Stdin.ReadMap(p.Config, func(m *stdio.Map) {
    21  		if match[m.Key] {
    22  			v, typeErr = types.ConvertGoType(m.Value, types.String)
    23  			if typeErr != nil {
    24  				p.Done()
    25  				return
    26  			}
    27  
    28  			p.Stdout.Writeln([]byte(v.(string)))
    29  		}
    30  	})
    31  
    32  	if typeErr != nil {
    33  		return typeErr
    34  	}
    35  
    36  	return err
    37  }