mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Implement review suggestions
This commit is contained in:
parent
7c7340c2e7
commit
4b2bfc3e8f
3 changed files with 19 additions and 19 deletions
|
@ -65,7 +65,7 @@ func printStack(_ *Request) (msg string, err error) {
|
|||
// debugInfo returns the debugging information for support requests.
|
||||
func debugInfo(ar *Request) (data []byte, err error) {
|
||||
// Create debug information helper.
|
||||
di := new(debug.DebugInfo)
|
||||
di := new(debug.Info)
|
||||
di.Style = ar.Request.URL.Query().Get("style")
|
||||
|
||||
// Add debug information.
|
||||
|
|
|
@ -13,40 +13,40 @@ import (
|
|||
"github.com/shirou/gopsutil/host"
|
||||
)
|
||||
|
||||
// DebugInfo gathers debugging information and stores everything in a buffer in
|
||||
// Info gathers debugging information and stores everything in a buffer in
|
||||
// order to write it to somewhere later. It directly inherits a bytes.Buffer,
|
||||
// so you can also use all these functions too.
|
||||
type DebugInfo struct {
|
||||
type Info struct {
|
||||
bytes.Buffer
|
||||
Style string
|
||||
}
|
||||
|
||||
// DebugInfoFlag defines possible options for adding sections to a DebugInfo.
|
||||
type DebugInfoFlag int
|
||||
// InfoFlag defines possible options for adding sections to a Info.
|
||||
type InfoFlag int
|
||||
|
||||
const (
|
||||
// NoFlags does nothing.
|
||||
NoFlags DebugInfoFlag = 0
|
||||
NoFlags InfoFlag = 0
|
||||
|
||||
// UseCodeSection wraps the section content in a markdown code section.
|
||||
UseCodeSection DebugInfoFlag = 1
|
||||
UseCodeSection InfoFlag = 1
|
||||
|
||||
// AddContentLineBreaks adds a line breaks after each line of content,
|
||||
// except for the last.
|
||||
AddContentLineBreaks DebugInfoFlag = 2
|
||||
AddContentLineBreaks InfoFlag = 2
|
||||
)
|
||||
|
||||
func useCodeSection(flags DebugInfoFlag) bool {
|
||||
func useCodeSection(flags InfoFlag) bool {
|
||||
return flags&UseCodeSection > 0
|
||||
}
|
||||
|
||||
func addContentLineBreaks(flags DebugInfoFlag) bool {
|
||||
func addContentLineBreaks(flags InfoFlag) bool {
|
||||
return flags&AddContentLineBreaks > 0
|
||||
}
|
||||
|
||||
// AddSection adds a debug section to the DebugInfo. The result is directly
|
||||
// AddSection adds a debug section to the Info. The result is directly
|
||||
// written into the buffer.
|
||||
func (di *DebugInfo) AddSection(name string, flags DebugInfoFlag, content ...string) {
|
||||
func (di *Info) AddSection(name string, flags InfoFlag, content ...string) {
|
||||
// Check if we need a spacer.
|
||||
if di.Len() > 0 {
|
||||
di.WriteString("\n\n")
|
||||
|
@ -84,7 +84,7 @@ func (di *DebugInfo) AddSection(name string, flags DebugInfoFlag, content ...str
|
|||
}
|
||||
|
||||
// AddVersionInfo adds version information from the info pkg.
|
||||
func (di *DebugInfo) AddVersionInfo() {
|
||||
func (di *Info) AddVersionInfo() {
|
||||
di.AddSection(
|
||||
"Version "+info.Version(),
|
||||
UseCodeSection,
|
||||
|
@ -93,7 +93,7 @@ func (di *DebugInfo) AddVersionInfo() {
|
|||
}
|
||||
|
||||
// AddPlatformInfo adds OS and platform information.
|
||||
func (di *DebugInfo) AddPlatformInfo(ctx context.Context) {
|
||||
func (di *Info) AddPlatformInfo(ctx context.Context) {
|
||||
// Get information from the system.
|
||||
info, err := host.InfoWithContext(ctx)
|
||||
if err != nil {
|
||||
|
@ -126,7 +126,7 @@ func (di *DebugInfo) AddPlatformInfo(ctx context.Context) {
|
|||
}
|
||||
|
||||
// AddGoroutineStack adds the current goroutine stack.
|
||||
func (di *DebugInfo) AddGoroutineStack() {
|
||||
func (di *Info) AddGoroutineStack() {
|
||||
buf := new(bytes.Buffer)
|
||||
err := pprof.Lookup("goroutine").WriteTo(buf, 1)
|
||||
if err != nil {
|
||||
|
@ -147,7 +147,7 @@ func (di *DebugInfo) AddGoroutineStack() {
|
|||
}
|
||||
|
||||
// AddLastReportedModuleError adds the last reported module error, if one exists.
|
||||
func (di *DebugInfo) AddLastReportedModuleError() {
|
||||
func (di *Info) AddLastReportedModuleError() {
|
||||
me := modules.GetLastReportedError()
|
||||
if me == nil {
|
||||
di.AddSection("No Module Error", NoFlags)
|
||||
|
@ -162,7 +162,7 @@ func (di *DebugInfo) AddLastReportedModuleError() {
|
|||
}
|
||||
|
||||
// AddLastUnexpectedLogs adds the last 10 unexpected log lines, if any.
|
||||
func (di *DebugInfo) AddLastUnexpectedLogs() {
|
||||
func (di *Info) AddLastUnexpectedLogs() {
|
||||
lines := log.GetLastUnexpectedLogs()
|
||||
|
||||
// Check if there is anything at all.
|
||||
|
|
|
@ -11,7 +11,7 @@ var (
|
|||
nameOnly = regexp.MustCompile("^[A-Za-z0-9]+$")
|
||||
delimitersAtStart = regexp.MustCompile("^[^A-Za-z0-9]+")
|
||||
delimitersOnly = regexp.MustCompile("^[^A-Za-z0-9]+$")
|
||||
cleanName = regexp.MustCompile(`["']`)
|
||||
removeQuotes = strings.NewReplacer(`"`, ``, `'`, ``)
|
||||
)
|
||||
|
||||
// GenerateBinaryNameFromPath generates a more human readable binary name from
|
||||
|
@ -70,7 +70,7 @@ func cleanFileDescription(fileDescr string) string {
|
|||
|
||||
// Clean out and `"` and `'`.
|
||||
for i := range fields {
|
||||
fields[i] = cleanName.ReplaceAllString(fields[i], "")
|
||||
fields[i] = removeQuotes.Replace(fields[i])
|
||||
}
|
||||
|
||||
// If there is a 1 or 2 character delimiter field, only use fields before it.
|
||||
|
|
Loading…
Add table
Reference in a new issue