Finish adding the goinfo page.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Captain ALM 2022-07-16 16:01:53 +01:00
parent da41214617
commit 187e7cec54
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
4 changed files with 356 additions and 4 deletions

View File

@ -1,10 +1,41 @@
package conf
import (
"os"
"path"
"path/filepath"
"strings"
)
type ServeYaml struct {
DataStorage string `yaml:"dataStorage"`
Domains []string `yaml:"domains"`
RangeSupported bool `yaml:"rangeSupported"`
FilterURLQueries bool `yaml:"filterURLQueries"`
EnableGoInfoPage bool `yaml:"enableGoInfoPage"`
CacheSettings CacheSettingsYaml `yaml:"cacheSettings"`
}
func (sy ServeYaml) GetDomainString() string {
if len(sy.Domains) == 0 {
return "all"
} else {
return strings.Join(sy.Domains, " ")
}
}
func (sy ServeYaml) GetDataStoragePath() string {
if sy.DataStorage == "" || !filepath.IsAbs(sy.DataStorage) {
wd, err := os.Getwd()
if err != nil {
return ""
} else {
if sy.DataStorage == "" {
return wd
} else {
return path.Join(wd, sy.DataStorage)
}
}
} else {
return sy.DataStorage
}
}

311
goinfo.go.html Normal file
View File

@ -0,0 +1,311 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex, nofollow, nositelinkssearchbox">
<title>Go Info</title>
<style>
.full-heading {
margin: auto;
width: 80%;
border: black 1px solid;
text-align: center;
background-color: mediumslateblue;
}
table, th, td {
margin: auto;
text-align: left;
border: black 1px solid;
border-collapse: collapse;
}
table, td {
background-color: lightgray;
}
table {
width: 80%;
}
th {
background-color: lightsteelblue;
width: 25%;
}
td {
width: 75%;
}
</style>
</head>
<body>
<p>
<div class="full-heading">
<h1>{{ .GoVersion }} - {{ .ProductName }}</h1>
</div>
</p>
<p>
{{ if .FullOutput }}
<div class="full-heading">
<b>
<a href="?">Less Output</a>
</b>
</div>
{{ else }}
<div class="full-heading">
<b>
<a href="?full">More Output</a>
</b>
</div>
{{ end }}
</p>
<p>
<table>
<tr>
<th>Product Name</th>
<td>{{ .ProductName }}</td>
</tr>
<tr>
<th>Product Description</th>
<td>{{ .ProductDescription }}</td>
</tr>
<tr>
<th>Product Location</th>
<td>{{ .ProductLocation }}</td>
</tr>
<tr>
<th>Build Commit</th>
<td>#{{ .BuildVersion }}</td>
</tr>
<tr>
<th>Build Date</th>
<td>{{ .BuildDate }}</td>
</tr>
<tr>
<th>Working Directory</th>
<td>{{ .WorkingDirectory }}</td>
</tr>
{{ if .FullOutput }}
<tr>
<th>Process ID</th>
<td>{{ .ProcessID }}</td>
</tr>
<tr>
<th>Parent Process ID</th>
<td>{{ .ParentProcessID }}</td>
</tr>
{{ end }}
</table>
</p>
<p>
<table>
<tr>
<th>Go Version</th>
<td>{{ .GoVersion }}</td>
</tr>
<tr>
<th>Go Toolchain</th>
<td>{{ .Compiler }}</td>
</tr>
<tr>
<th>GOROOT</th>
<td>{{ .GoRoot }}</td>
</tr>
<tr>
<th>GOMAXPROCS</th>
<td>{{ .GoMaxProcs }}</td>
</tr>
<tr>
<th>Go Routine Count</th>
<td>{{ .GoRoutineNum }}</td>
</tr>
<tr>
<th>Go c go call Count</th>
<td>{{ .GoCGoCallNum }}</td>
</tr>
</table>
</p>
<p>
<table>
<tr>
<th>Hostname</th>
<td>{{ .Hostname }}</td>
</tr>
<tr>
<th>Operating System</th>
<td>{{ .GoOS }}</td>
</tr>
<tr>
<th>Architecture</th>
<td>{{ .GoArch }}</td>
</tr>
<tr>
<th>Number of Cores</th>
<td>{{ .NumCPU }}</td>
</tr>
<tr>
<th>Memory Page Size</th>
<td>{{ .PageSize }}</td>
</tr>
</table>
</p>
<p>
<table>
<tr>
<th>Listen Type</th>
<td>{{ .ListenSettings.WebNetwork }}</td>
</tr>
<tr>
<th>Listening Address</th>
<td>{{ .ListenSettings.Web }}</td>
</tr>
<tr>
<th>Listening Method</th>
<td>{{ .ListenSettings.WebMethod }}</td>
</tr>
<tr>
<th>Identifying</th>
<td>{{ .ListenSettings.Identify }}</td>
</tr>
{{ if and .FullOutput .ListenSettings.Identify }}
<tr>
<th>Server</th>
<td>Clerie Gilbert</td>
</tr>
<tr>
<th>Powered By</th>
<td>Love</td>
</tr>
<tr>
<th>Friendly</th>
<td>True</td>
</tr>
{{ end }}
</table>
</p>
<p>
<table>
<tr>
<th>Template Storage Path</th>
<td>{{ .ServeSettings.GetDataStoragePath }}</td>
</tr>
<tr>
<th>Served Domains</th>
<td>{{ .ServeSettings.GetDomainString }}</td>
</tr>
<tr>
<th>Range Supported</th>
<td>{{ .ServeSettings.RangeSupported }}</td>
</tr>
</table>
</p>
{{ if .FullOutput }}
<p>
<table>
<tr>
<th>Enable Template Caching</th>
<td>{{ .ServeSettings.CacheSettings.EnableTemplateCaching }}</td>
</tr>
<tr>
<th>Enable Template Cache Purge</th>
<td>{{ .ServeSettings.CacheSettings.EnableTemplateCachePurge }}</td>
</tr>
<tr>
<th>Enable Content Caching</th>
<td>{{ .ServeSettings.CacheSettings.EnableContentsCaching }}</td>
</tr>
<tr>
<th>Enable Content Cache Purge</th>
<td>{{ .ServeSettings.CacheSettings.EnableContentsCachePurge }}</td>
</tr>
<tr>
<th>Max Age</th>
<td>{{ .ServeSettings.CacheSettings.MaxAge }}</td>
</tr>
<tr>
<th>Enable Last Modified Precondition Support</th>
<td>{{ .ServeSettings.CacheSettings.NotModifiedResponseUsingLastModified }}</td>
</tr>
<tr>
<th>Enable ETag Precondition Support</th>
<td>{{ .ServeSettings.CacheSettings.NotModifiedResponseUsingETags }}</td>
</tr>
</table>
</p>
<p>
<table>
<tr>
<th>Environment Variables</th>
</tr>
{{ range .Environment }}
<tr>
<td>{{ . }}</td>
</tr>
{{ end }}
</table>
</p>
{{ end }}
<p>
<table>
<tr>
<th>Number of Registered Pages</th>
<td>{{ len .RegisteredPages }}</td>
</tr>
</table>
</p>
{{ if and .FullOutput (not (eq (len .RegisteredPages) 0)) }}
<p>
<table>
<tr>
<th>Registered Pages</th>
</tr>
{{ range .RegisteredPages }}
<tr>
<td>{{ . }}</td>
</tr>
{{ end }}
</table>
</p>
{{ end }}
</p>
<p>
<table>
<tr>
<th>Number of Cached Pages</th>
<td>{{ len .CachedPages }}</td>
</tr>
</table>
</p>
{{ if and .FullOutput (not (eq (len .CachedPages) 0)) }}
<p>
<table>
<tr>
<th>Cached Pages</th>
</tr>
{{ range .CachedPages }}
<tr>
<td>{{ . }}</td>
</tr>
{{ end }}
</table>
</p>
{{ end }}
</p>
<p>
{{ if .FullOutput }}
<div class="full-heading">
<b>
<a href="?">Less Output</a>
</b>
</div>
{{ else }}
<div class="full-heading">
<b>
<a href="?full">More Output</a>
</b>
</div>
{{ end }}
</p>
</body>
</html>

View File

@ -20,12 +20,16 @@ func newGoInfoPage(handlerIn *PageHandler, dataStore string, cacheTemplates bool
if cacheTemplates {
ptm = &sync.Mutex{}
}
return &goInfoPage{
pageToReturn := &goInfoPage{
Handler: handlerIn,
DataStore: dataStore,
CacheTemplate: cacheTemplates,
PageTemplateMutex: ptm,
}
if !cacheTemplates {
_, _ = pageToReturn.getPageTemplate()
}
return pageToReturn
}
type goInfoPage struct {
@ -49,6 +53,7 @@ type goInfoTemplateMarshal struct {
RegisteredPages []string
CachedPages []string
ProcessID int
ParentProcessID int
ProductLocation string
ProductName string
ProductDescription string
@ -63,6 +68,9 @@ type goInfoTemplateMarshal struct {
NumCPU int
GoRoot string
GoMaxProcs int
Compiler string
GoArch string
GoOS string
ListenSettings conf.ListenYaml
ServeSettings conf.ServeYaml
Environment []string
@ -102,6 +110,7 @@ func (gipg *goInfoPage) GetContents(urlParameters url.Values) (contentType strin
RegisteredPages: regPages,
CachedPages: cacPages,
ProcessID: os.Getpid(),
ParentProcessID: os.Getppid(),
ProductLocation: getStringOrError(os.Executable),
ProductName: info.BuildName,
ProductDescription: info.BuildDescription,
@ -116,6 +125,9 @@ func (gipg *goInfoPage) GetContents(urlParameters url.Values) (contentType strin
NumCPU: runtime.NumCPU(),
GoRoot: runtime.GOROOT(),
GoMaxProcs: runtime.GOMAXPROCS(0),
Compiler: runtime.Compiler,
GoArch: runtime.GOARCH,
GoOS: runtime.GOOS,
ListenSettings: info.ListenSettings,
ServeSettings: info.ServeSettings,
Environment: env,

View File

@ -19,7 +19,6 @@ type PageHandler struct {
PageProviders map[string]PageProvider
pageContentsCacheRWMutex *sync.RWMutex
RangeSupported bool
FilterURLQueries bool
CacheSettings conf.CacheSettingsYaml
}
@ -40,7 +39,6 @@ func NewPageHandler(config conf.ServeYaml) *PageHandler {
PageContentsCache: thePCCMap,
pageContentsCacheRWMutex: theMutex,
RangeSupported: config.RangeSupported,
FilterURLQueries: config.FilterURLQueries,
CacheSettings: config.CacheSettings,
}
if config.EnableGoInfoPage {