Sandeep Singh b4644af80a
Lint + test fixes after utils dep update (#6393)
* fix: remove undefined errorutil.ShowStackTrace

* feat: add make lint support and integrate with test

* refactor: migrate errorutil to errkit across codebase

- Replace deprecated errorutil with modern errkit
- Convert error declarations from var to func for better compatibility
- Fix all SA1019 deprecation warnings
- Maintain error chain support and stack traces

* fix: improve DNS test reliability using Google DNS

- Configure test to use Google DNS (8.8.8.8) for stability
- Fix nil pointer issue in DNS client initialization
- Keep production defaults unchanged

* fixing logic

* removing unwanted branches in makefile

---------

Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
2025-08-20 05:28:23 +05:30

66 lines
1.5 KiB
Go

package util
import (
"bytes"
"fmt"
"strings"
"github.com/projectdiscovery/utils/errkit"
)
func CreateLink(title string, url string) string {
return fmt.Sprintf("[%s](%s)", title, url)
}
func MakeBold(text string) string {
return "**" + text + "**"
}
func CreateTable(headers []string, rows [][]string) (string, error) {
builder := &bytes.Buffer{}
headerSize := len(headers)
if headers == nil || headerSize == 0 {
return "", errkit.New("No headers provided").Build()
}
builder.WriteString(CreateTableHeader(headers...))
for _, row := range rows {
rowSize := len(row)
if rowSize == headerSize {
builder.WriteString(CreateTableRow(row...))
} else if rowSize < headerSize {
extendedRows := make([]string, headerSize)
copy(extendedRows, row)
builder.WriteString(CreateTableRow(extendedRows...))
} else {
return "", errkit.New("Too many columns for the given headers").Build()
}
}
return builder.String(), nil
}
func CreateTableHeader(headers ...string) string {
headerSize := len(headers)
if headers == nil || headerSize == 0 {
return ""
}
return CreateTableRow(headers...) +
"|" + strings.Repeat(" --- |", headerSize) + "\n"
}
func CreateTableRow(elements ...string) string {
return fmt.Sprintf("| %s |\n", strings.Join(elements, " | "))
}
func CreateHeading3(text string) string {
return "### " + text + "\n"
}
func CreateHorizontalLine() string {
// for regular markdown 3 dashes are enough, but for Jira the minimum is 4
return "----\n"
}