hi,
I am trying to parse he output of a command and not getting the desired
results.
This is the sanitized output:
Certificate
DN: O=SUB,DOMAIN.TLD, CN=usernamej
Serial: 333333
Serialized id:
pkcs11:model=PKCS%2315%20emulated;token=1;manufacturer=piv_II;serial=xxxxxxxxxxxxxxxxxxxxxx;id=%08
Certificate
DN: O=OTHER.DOMAIN.TLD, CN=yetanother0.other.domain.tld
Serial: 4444
Serialized id:
pkcs11:model=PKCS%2315%20emulated;token=1;manufacturer=piv_II;serial=xxxxxxxxxxxxxxxxxxxx;id=%09
Skipping the part to run the command etc, that works:
ype ykcert struct {
DN string
Serial string
Serializedid string
}
certnr := 0
var certs = make(map[int]ykcert)
var certregex = regexp.MustCompile(`^Certificate`)
var dnregex = regexp.MustCompile(`\s+DN:\s+`)
var serialregex = regexp.MustCompile(`\s+Serial:`)
var serialidregex = regexp.MustCompile(`\s+Serialized id:`)
scanner := bufio.NewScanner(r)
go func() {
for scanner.Scan() {
if len(scanner.Text()) < 1 {
continue
}
switch {
case certregex.MatchString(scanner.Text()):
certnr++
case dnregex.MatchString(scanner.Text()):
certs[certnr] = ykcert{DN: scanner.Text()}
case serialregex.MatchString(scanner.Text()):
certs[certnr] = ykcert{Serial: scanner.Text()}
case serialidregex.MatchString(scanner.Text()):
certs[certnr] = ykcert{Serializedid: scanner.Text()}
}
}
done <- struct{}{}
}()
So I try to save the output in a map which is map[int]ykcert and while
scanning the text if I match the desired regex, I assign that to the struct
field.
What happens is that only the last case is 'remembered', so the map gets
the correct number of elements, but the struct only gets filed with, in
this case, the serializedid field. The other fields are not there.
How can I fill in the map elements fully?
Thanks for your input.
--
regards,
Natxo
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/4ef97f93-284a-4cd2-bc19-f9fdd3bcf0een%40googlegroups.com.