nuclei/v2/pkg/utils/utils.go
Sajad Parra d1303797c0 * Add support to run remote template
* Add remote-template-domain config only flag to specify allowed domain list to load remote templates from
2022-01-12 18:33:17 +05:30

56 lines
981 B
Go

package utils
import (
"errors"
"net/url"
"strings"
"github.com/projectdiscovery/fileutil"
)
func IsBlank(value string) bool {
return strings.TrimSpace(value) == ""
}
func IsNotBlank(value string) bool {
return !IsBlank(value)
}
func UnwrapError(err error) error {
for { // get the last wrapped error
unwrapped := errors.Unwrap(err)
if unwrapped == nil {
break
}
err = unwrapped
}
return err
}
func LoadFile(filename string) ([]string, error) {
var items []string
readfileChan, err := fileutil.ReadFile(filename)
if err != nil {
return nil, err
}
for includeIdLine := range readfileChan {
items = append(items, includeIdLine)
}
return items, nil
}
// IsURL tests a string to determine if it is a well-structured url or not.
func IsURL(input string) bool {
_, err := url.ParseRequestURI(input)
if err != nil {
return false
}
u, err := url.Parse(input)
if err != nil || u.Scheme == "" || u.Host == "" {
return false
}
return true
}