Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Instance ¶
type Instance struct { Name string Status string Error error CurrentReplicas int32 DesiredReplicas int32 }
Instance holds the current state about an instance
type Options ¶
type Options struct { DisplayName string ShowDetails bool InstanceStates []Instance SessionDuration time.Duration RefreshFrequency time.Duration }
Options holds the customizable input to template
type Themes ¶
type Themes struct {
// contains filtered or unexported fields
}
func (*Themes) Render ¶
Example ¶
package main import ( "fmt" "os" "testing/fstest" "time" "github.com/acouvreur/sablier/app/theme" "github.com/acouvreur/sablier/version" ) var ( StartingInstanceInfo = theme.Instance{ Name: "starting-instance", Status: "instance is starting...", Error: nil, CurrentReplicas: 0, DesiredReplicas: 1, } StartedInstanceInfo = theme.Instance{ Name: "started-instance", Status: "instance is started.", Error: nil, CurrentReplicas: 1, DesiredReplicas: 1, } ErrorInstanceInfo = theme.Instance{ Name: "error-instance", Error: fmt.Errorf("instance does not exist"), CurrentReplicas: 0, DesiredReplicas: 1, } ) func main() { const customTheme = ` <html lang="en"> <head> <meta http-equiv="refresh" content="{{ .RefreshFrequency }}" /> </head> <body> Starting {{ .DisplayName }} Your instances will stop after {{ .SessionDuration }} of inactivity <table> {{- range $i, $instance := .InstanceStates }} <tr> <td>{{ $instance.Name }}</td> {{- if $instance.Error }} <td>{{ $instance.Error }}</td> {{- else }} <td>{{ $instance.Status }} ({{ $instance.CurrentReplicas }}/{{ $instance.DesiredReplicas }})</td> {{- end}} </tr> {{- end }} </table> Sablier version {{ .Version }} </body> </html> ` version.Version = "1.0.0" themes, err := theme.NewWithCustomThemes(fstest.MapFS{ "inner/custom-theme.html": &fstest.MapFile{Data: []byte(customTheme)}, }) if err != nil { panic(err) } instances := []theme.Instance{ StartingInstanceInfo, StartedInstanceInfo, ErrorInstanceInfo, } err = themes.Render("custom-theme", theme.Options{ DisplayName: "Test", InstanceStates: instances, ShowDetails: true, SessionDuration: 10 * time.Minute, RefreshFrequency: 5 * time.Second, }, os.Stdout) if err != nil { panic(err) } }
Output: <html lang="en"> <head> <meta http-equiv="refresh" content="5" /> </head> <body> Starting Test Your instances will stop after 10 minutes of inactivity <table> <tr> <td>starting-instance</td> <td>instance is starting... (0/1)</td> </tr> <tr> <td>started-instance</td> <td>instance is started. (1/1)</td> </tr> <tr> <td>error-instance</td> <td>instance does not exist</td> </tr> </table> Sablier version 1.0.0 </body> </html>
Click to show internal directories.
Click to hide internal directories.