1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-02-01 13:08:02 +02:00
mailpit/utils/tools/html.go
2023-08-16 16:59:31 +12:00

20 lines
390 B
Go

package tools
import (
"fmt"
"golang.org/x/net/html"
)
// GetHTMLAttributeVal returns the value of an HTML Attribute, else an error.
// Returns a blank value if the attribute is set but empty.
func GetHTMLAttributeVal(e *html.Node, key string) (string, error) {
for _, a := range e.Attr {
if a.Key == key {
return a.Val, nil
}
}
return "", fmt.Errorf("%s not found", key)
}