Commit 03c9f562 authored by santiaago's avatar santiaago
Browse files

add theme controller #31

parent c04d2a98
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import (
	"github.com/taironas/tinygraphs/controllers/isogrids"
	"github.com/taironas/tinygraphs/controllers/spaceinvaders"
	"github.com/taironas/tinygraphs/controllers/squares"
	"github.com/taironas/tinygraphs/controllers/themes"
)

var root = flag.String("root", "app", "file system path")
@@ -33,6 +34,7 @@ func main() {
	r.HandleFunc("/isogrids/:key", isogrids.Isogrids)
	r.HandleFunc("/spaceinvaders/:key", spaceinvaders.SpaceInvaders)

	r.HandleFunc("/themes/:theme", themes.Theme)
	r.HandleFunc("/labs/checkerboard", checkerboard.Checkerboard)
	r.HandleFunc("/labs/squares/random", squares.Random)
	r.HandleFunc("/labs/isogrids/hexa", isogrids.Hexa)
+26 −0
Original line number Diff line number Diff line
package themes

import (
	"log"
	"net/http"

	"github.com/taironas/route"
	"github.com/taironas/tinygraphs/colors"
)

// Theme handler builds an image with the colors of a theme
// the theme is defined by keyword :theme
// url: "/themes/:theme"
func Theme(w http.ResponseWriter, r *http.Request) {

	var err error
	var theme string
	if theme, _ = route.Context.Get(r, "theme"); err != nil {
		theme = "base"
	}

	colorMap := colors.MapOfColorThemes()
	if val, ok := colorMap[theme]; ok {
		log.Println(val)
	}
}