From 187e7cec545327a22c1d9f2ee438df65b4ebf580 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Sat, 16 Jul 2022 16:01:53 +0100 Subject: [PATCH] Finish adding the goinfo page. --- conf/serve.go | 33 +++- goinfo.go.html | 311 ++++++++++++++++++++++++++++++++++++ pageHandler/go-info-page.go | 14 +- pageHandler/page-handler.go | 2 - 4 files changed, 356 insertions(+), 4 deletions(-) create mode 100644 goinfo.go.html diff --git a/conf/serve.go b/conf/serve.go index e68fb79..a034205 100644 --- a/conf/serve.go +++ b/conf/serve.go @@ -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 + } +} diff --git a/goinfo.go.html b/goinfo.go.html new file mode 100644 index 0000000..3269a0a --- /dev/null +++ b/goinfo.go.html @@ -0,0 +1,311 @@ + + + + + + + Go Info + + + +

+

+

{{ .GoVersion }} - {{ .ProductName }}

+
+

+

+ {{ if .FullOutput }} +

+ + Less Output + +
+{{ else }} +
+ + More Output + +
+{{ end }} +

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + {{ if .FullOutput }} + + + + + + + + + {{ end }} +
Product Name{{ .ProductName }}
Product Description{{ .ProductDescription }}
Product Location{{ .ProductLocation }}
Build Commit#{{ .BuildVersion }}
Build Date{{ .BuildDate }}
Working Directory{{ .WorkingDirectory }}
Process ID{{ .ProcessID }}
Parent Process ID{{ .ParentProcessID }}
+

+

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Go Version{{ .GoVersion }}
Go Toolchain{{ .Compiler }}
GOROOT{{ .GoRoot }}
GOMAXPROCS{{ .GoMaxProcs }}
Go Routine Count{{ .GoRoutineNum }}
Go c go call Count{{ .GoCGoCallNum }}
+

+

+ + + + + + + + + + + + + + + + + + + + + +
Hostname{{ .Hostname }}
Operating System{{ .GoOS }}
Architecture{{ .GoArch }}
Number of Cores{{ .NumCPU }}
Memory Page Size{{ .PageSize }}
+

+

+ + + + + + + + + + + + + + + + + + {{ if and .FullOutput .ListenSettings.Identify }} + + + + + + + + + + + + + {{ end }} +
Listen Type{{ .ListenSettings.WebNetwork }}
Listening Address{{ .ListenSettings.Web }}
Listening Method{{ .ListenSettings.WebMethod }}
Identifying{{ .ListenSettings.Identify }}
ServerClerie Gilbert
Powered ByLove
FriendlyTrue
+

+

+ + + + + + + + + + + + + +
Template Storage Path{{ .ServeSettings.GetDataStoragePath }}
Served Domains{{ .ServeSettings.GetDomainString }}
Range Supported{{ .ServeSettings.RangeSupported }}
+

+{{ if .FullOutput }} +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Enable Template Caching{{ .ServeSettings.CacheSettings.EnableTemplateCaching }}
Enable Template Cache Purge{{ .ServeSettings.CacheSettings.EnableTemplateCachePurge }}
Enable Content Caching{{ .ServeSettings.CacheSettings.EnableContentsCaching }}
Enable Content Cache Purge{{ .ServeSettings.CacheSettings.EnableContentsCachePurge }}
Max Age{{ .ServeSettings.CacheSettings.MaxAge }}
Enable Last Modified Precondition Support{{ .ServeSettings.CacheSettings.NotModifiedResponseUsingLastModified }}
Enable ETag Precondition Support{{ .ServeSettings.CacheSettings.NotModifiedResponseUsingETags }}
+

+

+ + + + + {{ range .Environment }} + + + + {{ end }} +
Environment Variables
{{ . }}
+

+{{ end }} +

+ + + + + +
Number of Registered Pages{{ len .RegisteredPages }}
+

+{{ if and .FullOutput (not (eq (len .RegisteredPages) 0)) }} +

+ + + + + {{ range .RegisteredPages }} + + + + {{ end }} +
Registered Pages
{{ . }}
+

+{{ end }} +

+

+ + + + + +
Number of Cached Pages{{ len .CachedPages }}
+

+{{ if and .FullOutput (not (eq (len .CachedPages) 0)) }} +

+ + + + + {{ range .CachedPages }} + + + + {{ end }} +
Cached Pages
{{ . }}
+

+{{ end }} +

+

+ {{ if .FullOutput }} +

+ + Less Output + +
+{{ else }} +
+ + More Output + +
+{{ end }} +

+ + \ No newline at end of file diff --git a/pageHandler/go-info-page.go b/pageHandler/go-info-page.go index 8ee6b95..99da92d 100644 --- a/pageHandler/go-info-page.go +++ b/pageHandler/go-info-page.go @@ -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, diff --git a/pageHandler/page-handler.go b/pageHandler/page-handler.go index 9c71d93..87f269a 100644 --- a/pageHandler/page-handler.go +++ b/pageHandler/page-handler.go @@ -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 {