Skip to content

Commit

Permalink
Add config options for UI color and title
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Dec 7, 2015
1 parent 7233c8e commit e9b09cc
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 16 deletions.
7 changes: 5 additions & 2 deletions admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import (

"github.com/eBay/fabio/admin/api"
"github.com/eBay/fabio/admin/ui"
"github.com/eBay/fabio/config"
)

// ListenAndServe starts the admin api and ui server.
func ListenAndServe(addr, version string) error {
func ListenAndServe(cfg config.UI, version string) error {
ui.Version = version
ui.Color = cfg.Color
ui.Title = cfg.Title
http.HandleFunc("/api/manual", api.HandleManual)
http.HandleFunc("/api/routes", api.HandleRoutes)
http.HandleFunc("/manual", ui.HandleManual)
http.HandleFunc("/routes", ui.HandleRoutes)
http.HandleFunc("/health", handleHealth)
http.Handle("/", http.RedirectHandler("/routes", http.StatusSeeOther))
return http.ListenAndServe(addr, nil)
return http.ListenAndServe(cfg.Addr, nil)
}

func handleHealth(w http.ResponseWriter, r *http.Request) {
Expand Down
12 changes: 8 additions & 4 deletions admin/ui/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (

// HandleManual provides the UI for the manual overrides.
func HandleManual(w http.ResponseWriter, r *http.Request) {
data := struct{ Version string }{Version}
data := struct {
Color string
Title string
Version string
}{Color, Title, Version}
tmplManual.ExecuteTemplate(w, "manual", data)
}

Expand All @@ -16,7 +20,7 @@ var tmplManual = template.Must(template.New("manual").Parse(`
<html lang="en">
<head>
<meta charset="utf-8">
<title>./fabio</title>
<title>./fabio{{if .Title}} - {{.Title}}{{end}}</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/js/materialize.min.js"></script>
Expand All @@ -27,11 +31,11 @@ var tmplManual = template.Must(template.New("manual").Parse(`
</head>
<body>
<nav class="top-nav light-green">
<nav class="top-nav {{.Color}}">
<div class="container">
<div class="nav-wrapper">
<a href="/" class="brand-logo">./fabio</a>
<a href="/" class="brand-logo">./fabio{{if .Title}} - {{.Title}}{{end}}</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="/routes">Routes</a></li>
<li><a href="https://github.com/eBay/fabio/blob/master/CHANGELOG.md">{{.Version}}</a></li>
Expand Down
12 changes: 8 additions & 4 deletions admin/ui/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (

// HandleRoutes provides the UI for managing the routing table.
func HandleRoutes(w http.ResponseWriter, r *http.Request) {
data := struct{ Version string }{Version}
data := struct {
Color string
Title string
Version string
}{Color, Title, Version}
tmplRoutes.ExecuteTemplate(w, "routes", data)
}

Expand All @@ -16,7 +20,7 @@ var tmplRoutes = template.Must(template.New("routes").Parse(`
<html lang="en">
<head>
<meta charset="utf-8">
<title>./fabio</title>
<title>./fabio{{if .Title}} - {{.Title}}{{end}}</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/js/materialize.min.js"></script>
Expand All @@ -37,11 +41,11 @@ var tmplRoutes = template.Must(template.New("routes").Parse(`
</head>
<body>
<nav class="top-nav light-green">
<nav class="top-nav {{.Color}}">
<div class="container">
<div class="nav-wrapper">
<a href="/" class="brand-logo">./fabio</a>
<a href="/" class="brand-logo">./fabio{{if .Title}} - {{.Title}}{{end}}</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="/manual">Overrides</a></li>
<li><a href="https://github.com/eBay/fabio/blob/master/CHANGELOG.md">{{.Version}}</a></li>
Expand Down
8 changes: 7 additions & 1 deletion admin/ui/ui.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Package ui provides the HTML admin console.
package ui

// Version contains the current fabio version
// Color contains the color of the nav bar.
var Color string

// Title contains an optional title for the nav bar.
var Title string

// Version contains the current fabio version.
var Version string
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ type Listen struct {
}

type UI struct {
Addr string
Addr string
Color string
Title string
}

type Proxy struct {
Expand Down
3 changes: 2 additions & 1 deletion config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var DefaultConfig = &Config{
GOMAXPROCS: runtime.NumCPU(),
},
UI: UI{
Addr: ":9998",
Addr: ":9998",
Color: "light-green",
},
}
4 changes: 3 additions & 1 deletion config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func FromProperties(p *properties.Properties) (cfg *Config, err error) {
}

cfg.UI = UI{
Addr: p.GetString("ui.addr", DefaultConfig.UI.Addr),
Addr: p.GetString("ui.addr", DefaultConfig.UI.Addr),
Color: p.GetString("ui.color", DefaultConfig.UI.Color),
Title: p.GetString("ui.title", DefaultConfig.UI.Title),
}

return cfg, nil
Expand Down
6 changes: 5 additions & 1 deletion config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ metrics.graphite.addr = 5.6.7.8:9999
runtime.gogc = 666
runtime.gomaxprocs = 12
ui.addr = 7.8.9.0:1234
ui.color = fonzy
ui.title = fabfab
`
out := &Config{
Proxy: Proxy{
Expand Down Expand Up @@ -76,7 +78,9 @@ ui.addr = 7.8.9.0:1234
GOMAXPROCS: 12,
},
UI: UI{
Addr: "7.8.9.0:1234",
Addr: "7.8.9.0:1234",
Color: "fonzy",
Title: "fabfab",
},
}

Expand Down
15 changes: 15 additions & 0 deletions fabio.properties
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,18 @@
# The default is
#
# ui.addr = :9998


# ui.color configures the background color of the UI.
# Color names are from http://materializecss.com/color.html
#
# The default is
#
# ui.color = light-green


# ui.title configures an optional title for the UI.
#
# The default is
#
# ui.title =
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func newProxy(cfg *config.Config) *proxy.Proxy {
func startAdmin(cfg *config.Config) {
log.Printf("[INFO] Admin server listening on %q", cfg.UI.Addr)
go func() {
if err := admin.ListenAndServe(cfg.UI.Addr, version); err != nil {
if err := admin.ListenAndServe(cfg.UI, version); err != nil {
log.Fatal("[FATAL] ui: ", err)
}
}()
Expand Down

0 comments on commit e9b09cc

Please sign in to comment.