File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55header {
66 background-color : {{.HeaderColor }};
77 color : # fff ;
8- font- size: 2rem ;
8+ font- size: 1rem ;
99 padding: 1rem;
1010}
1111main {
1212 padding : 1rem ;
1313}
14+ label {
15+ display : inline-block;
16+ width : {{.Form .Width }}em;
17+ }
Original file line number Diff line number Diff line change @@ -31,10 +31,27 @@ type LandingConfig struct {
3131 CSS string // CSS style tag for the landing page.
3232 Name string // The name of the exporter, generally suffixed by _exporter.
3333 Description string // A short description about the exporter.
34+ Form LandingForm // A POST form.
3435 Links []LandingLinks // Links displayed on the landing page.
3536 Version string // The version displayed.
3637}
3738
39+ // LandingForm provides a configuration struct for creating a POST form on the landing page.
40+ type LandingForm struct {
41+ Action string
42+ Inputs []LandingFormInput
43+ Width float64
44+ }
45+
46+ // LandingFormInput represents a single form input field.
47+ type LandingFormInput struct {
48+ Label string
49+ Type string
50+ Name string
51+ Placeholder string
52+ Value string
53+ }
54+
3855type LandingLinks struct {
3956 Address string // The URL the link points to.
4057 Text string // The text of the link.
5471
5572func NewLandingPage (c LandingConfig ) (* LandingPageHandler , error ) {
5673 var buf bytes.Buffer
74+
75+ length := 0
76+ for _ , input := range c .Form .Inputs {
77+ inputLength := len (input .Label )
78+ if inputLength > length {
79+ length = inputLength
80+ }
81+ }
82+ c .Form .Width = (float64 (length ) + 1 ) / 2
5783 if c .CSS == "" {
5884 if c .HeaderColor == "" {
5985 // Default to Prometheus orange.
Original file line number Diff line number Diff line change @@ -19,6 +19,16 @@ <h1>{{.Name}}</h1>
1919 {{ end }}
2020 </ ul >
2121 </ div >
22+ {{ if .Form.Action }}
23+ < div >
24+ < form action ="{{ .Form.Action}} ">
25+ {{ range .Form.Inputs }}
26+ < label > {{ .Label }}:</ label > < input type ="{{ .Type }} " name ="{{ .Name }} " placeholder =" .Placeholder }} " value ="{{ .Value }} "> < br >
27+ {{ end }}
28+ < input type ="submit " value ="Submit ">
29+ </ form >
30+ </ div >
31+ {{ end }}
2232 </ main >
2333 </ body >
2434</ html >
You can’t perform that action at this time.
0 commit comments