@@ -82,13 +82,14 @@ var loginTemplateHTML string
8282var loginCSS string
8383
8484type adminDashboardData struct {
85- ActiveTab string
86- Providers []service.ProviderWithStats
87- Accounts []service.AccountStats
88- NextToken * string
89- PrevToken * string
90- Error string
91- CSS template.CSS
85+ ActiveTab string
86+ Providers []service.ProviderWithStats
87+ Accounts []service.AccountStats
88+ NextToken * string
89+ PrevToken * string
90+ Error string
91+ CSS template.CSS
92+ EgressDollarsPerTiB float64
9293}
9394
9495type loginData struct {
@@ -118,6 +119,12 @@ func formatDate(t interface{}) string {
118119 return fmt .Sprintf ("%v" , t )
119120}
120121
122+ func formatDollars (bytes uint64 , dollarsPerTiB float64 ) string {
123+ const bytesPerTiB = 1024 * 1024 * 1024 * 1024
124+ dollars := (float64 (bytes ) / bytesPerTiB ) * dollarsPerTiB
125+ return fmt .Sprintf ("$%.2f" , dollars )
126+ }
127+
121128// showLoginForm renders the login form
122129func showLoginForm (w http.ResponseWriter , r * http.Request , errorMsg string ) {
123130 tmpl := template .Must (template .New ("login" ).Parse (loginTemplateHTML ))
@@ -221,17 +228,19 @@ func BasicAuthMiddleware(handler http.HandlerFunc, username, password string) ht
221228}
222229
223230// AdminHandler returns an HTTP handler for the admin dashboard
224- func AdminHandler (svc StatsService ) http.HandlerFunc {
231+ func AdminHandler (svc StatsService , egressDollarsPerTiB float64 ) http.HandlerFunc {
225232 tmpl := template .Must (template .New ("admin" ).Funcs (template.FuncMap {
226- "formatBytes" : formatBytes ,
227- "formatDate" : formatDate ,
233+ "formatBytes" : formatBytes ,
234+ "formatDate" : formatDate ,
235+ "formatDollars" : formatDollars ,
228236 }).Parse (adminTemplateHTML ))
229237
230238 const defaultLimit = 20
231239
232240 return func (w http.ResponseWriter , r * http.Request ) {
233241 data := adminDashboardData {
234- CSS : template .CSS (adminCSS ),
242+ CSS : template .CSS (adminCSS ),
243+ EgressDollarsPerTiB : egressDollarsPerTiB ,
235244 }
236245
237246 // Get active tab from query parameter (default to "providers")
0 commit comments