Loading app-backend/main.go +9 −8 Original line number Diff line number Diff line Loading @@ -3,7 +3,8 @@ package main import ( "flag" "github.com/taironas/route" "github.com/taironas/tinygraphs/controllers/grid" "github.com/taironas/tinygraphs/controllers/checkerboard" "github.com/taironas/tinygraphs/controllers/squares" "log" "net/http" "os" Loading @@ -14,14 +15,14 @@ var root = flag.String("root", "app", "file system path") func main() { r := new(route.Router) r.HandleFunc("/grid/?", grid.H6X6) r.HandleFunc("/grid/[0-8]/?", grid.Color) r.HandleFunc("/checkerboard/?", checkerboard.Checkerboard) r.HandleFunc("/checkerboard/[0-8]/?", checkerboard.Color) r.HandleFunc("/squares/?", grid.Random) r.HandleFunc("/squares/random/?", grid.Random) r.HandleFunc("/squares/random/[0-8]/?", grid.RandomColor) r.HandleFunc("/squares/[a-zA-Z0-9]+/?", grid.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9]+/?", grid.SquareColor) // cached r.HandleFunc("/squares/?", squares.Random) r.HandleFunc("/squares/random/?", squares.Random) r.HandleFunc("/squares/random/[0-8]/?", squares.RandomColor) r.HandleFunc("/squares/[a-zA-Z0-9]+/?", squares.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9]+/?", squares.Color) // cached r.AddStaticResource(root) Loading app/partials/marketing/example.html +2 −2 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ <h2 class="text-center" id="examples">EXAMPLE</h2> <div class="row"> <div class="col-md-3"> <img class="featurette-image img-responsive img-thumbnail" src="/grid" alt="grid image"> <img class="featurette-image img-responsive img-thumbnail" src="/checkerboard" alt="grid image"> </div> <div class="col-md-3"> <img class="featurette-image img-responsive img-thumbnail" src="/squares/random/1" alt="random black an white avatar"> Loading @@ -19,7 +19,7 @@ </div> <!-- /.row --> <div class="row"> <div class="col-md-3"> <code>/grid</code> <code>/checkerboard</code> </div> <div class="col-md-3"> <code>/squares/random/1</code> Loading controllers/grid/grid.go→controllers/checkerboard/checkerboard.go +21 −6 Original line number Diff line number Diff line package grid package checkerboard import ( "github.com/taironas/tinygraphs/colors" Loading @@ -9,10 +9,11 @@ import ( "image/color" "log" "net/http" "strconv" ) // gridColorHandler is the handler for /grid/[0-8] // build a 6x6 grid with alternate colors based on the number passed in the url // Color is the handler for /checkerboard/[0-8] // build a 6x6 checkerboard with alternate colors based on the number passed in the url func Color(w http.ResponseWriter, r *http.Request) { intID, err := misc.PermalinkID(r, 2) if err != nil { Loading @@ -27,9 +28,9 @@ func Color(w http.ResponseWriter, r *http.Request) { } } // grid6X6Handler is the handler for /grid/ // build a 6x6 grid with alternate black and white colors. func H6X6(w http.ResponseWriter, r *http.Request) { // Checkerboard is the handler for /checkerboard/ // build a 6x6 checkerboard with alternate black and white colors. func Checkerboard(w http.ResponseWriter, r *http.Request) { size := size(r) m := image.NewRGBA(image.Rect(0, 0, size, size)) color1 := color.RGBA{uint8(255), uint8(255), 255, 255} Loading @@ -38,3 +39,17 @@ func H6X6(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.Image(w, &img) } // extract size from HTTP request and return it. func size(r *http.Request) int { strSize := r.FormValue("size") if len(strSize) > 0 { if size, errSize := strconv.ParseInt(strSize, 0, 64); errSize == nil { isize := int(size) if isize > 0 && isize < 1000 { return int(size) } } } return 240 } controllers/grid/random.go→controllers/squares/random.go +1 −1 Original line number Diff line number Diff line package grid package squares import ( "github.com/taironas/tinygraphs/colors" Loading controllers/grid/square.go→controllers/squares/square.go +7 −4 Original line number Diff line number Diff line package grid package squares import ( "crypto/md5" Loading @@ -16,7 +16,7 @@ import ( "strings" ) // Square is the handler for /square/[A-Za-z0-9]+/? // Square is the handler for /squares/[A-Za-z0-9]+/? // build a 6x6 grid with alternate colors based on the number passed in the url func Square(w http.ResponseWriter, r *http.Request) { Loading Loading @@ -57,9 +57,9 @@ func Square(w http.ResponseWriter, r *http.Request) { } } // gridColorHandler is the handler for /square/[0-8]/[a-zA-Z0-9]+/? // Color is the handler for /square/[0-8]/[a-zA-Z0-9]+/? // build a 6x6 grid with alternate colors based on the number passed in the url func SquareColor(w http.ResponseWriter, r *http.Request) { func Color(w http.ResponseWriter, r *http.Request) { if colorId, err := misc.PermalinkID(r, 2); err != nil { log.Printf("error when extracting permalink id: %v", err) Loading Loading @@ -95,6 +95,7 @@ func SquareColor(w http.ResponseWriter, r *http.Request) { } } // extract hexadecimal code background from HTTP request and return color.RGBA func background(req *http.Request) (color.RGBA, error) { bg := req.FormValue("bg") if len(bg) == 0 { Loading @@ -104,6 +105,7 @@ func background(req *http.Request) (color.RGBA, error) { return color.RGBA{uint8(r), uint8(g), uint8(b), uint8(255)}, err } // extract hexadecimal code foreground from HTTP request and return color.RGBA func foreground(req *http.Request) (color.RGBA, error) { fg := req.FormValue("fg") if len(fg) == 0 { Loading Loading @@ -131,6 +133,7 @@ func hexToRGB(h string) (uint8, uint8, uint8, error) { return 0, 0, 0, nil } // extract size from HTTP request and return it. func size(r *http.Request) int { strSize := r.FormValue("size") if len(strSize) > 0 { Loading Loading
app-backend/main.go +9 −8 Original line number Diff line number Diff line Loading @@ -3,7 +3,8 @@ package main import ( "flag" "github.com/taironas/route" "github.com/taironas/tinygraphs/controllers/grid" "github.com/taironas/tinygraphs/controllers/checkerboard" "github.com/taironas/tinygraphs/controllers/squares" "log" "net/http" "os" Loading @@ -14,14 +15,14 @@ var root = flag.String("root", "app", "file system path") func main() { r := new(route.Router) r.HandleFunc("/grid/?", grid.H6X6) r.HandleFunc("/grid/[0-8]/?", grid.Color) r.HandleFunc("/checkerboard/?", checkerboard.Checkerboard) r.HandleFunc("/checkerboard/[0-8]/?", checkerboard.Color) r.HandleFunc("/squares/?", grid.Random) r.HandleFunc("/squares/random/?", grid.Random) r.HandleFunc("/squares/random/[0-8]/?", grid.RandomColor) r.HandleFunc("/squares/[a-zA-Z0-9]+/?", grid.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9]+/?", grid.SquareColor) // cached r.HandleFunc("/squares/?", squares.Random) r.HandleFunc("/squares/random/?", squares.Random) r.HandleFunc("/squares/random/[0-8]/?", squares.RandomColor) r.HandleFunc("/squares/[a-zA-Z0-9]+/?", squares.Square) //cached r.HandleFunc("/squares/[0-8]/[a-zA-Z0-9]+/?", squares.Color) // cached r.AddStaticResource(root) Loading
app/partials/marketing/example.html +2 −2 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ <h2 class="text-center" id="examples">EXAMPLE</h2> <div class="row"> <div class="col-md-3"> <img class="featurette-image img-responsive img-thumbnail" src="/grid" alt="grid image"> <img class="featurette-image img-responsive img-thumbnail" src="/checkerboard" alt="grid image"> </div> <div class="col-md-3"> <img class="featurette-image img-responsive img-thumbnail" src="/squares/random/1" alt="random black an white avatar"> Loading @@ -19,7 +19,7 @@ </div> <!-- /.row --> <div class="row"> <div class="col-md-3"> <code>/grid</code> <code>/checkerboard</code> </div> <div class="col-md-3"> <code>/squares/random/1</code> Loading
controllers/grid/grid.go→controllers/checkerboard/checkerboard.go +21 −6 Original line number Diff line number Diff line package grid package checkerboard import ( "github.com/taironas/tinygraphs/colors" Loading @@ -9,10 +9,11 @@ import ( "image/color" "log" "net/http" "strconv" ) // gridColorHandler is the handler for /grid/[0-8] // build a 6x6 grid with alternate colors based on the number passed in the url // Color is the handler for /checkerboard/[0-8] // build a 6x6 checkerboard with alternate colors based on the number passed in the url func Color(w http.ResponseWriter, r *http.Request) { intID, err := misc.PermalinkID(r, 2) if err != nil { Loading @@ -27,9 +28,9 @@ func Color(w http.ResponseWriter, r *http.Request) { } } // grid6X6Handler is the handler for /grid/ // build a 6x6 grid with alternate black and white colors. func H6X6(w http.ResponseWriter, r *http.Request) { // Checkerboard is the handler for /checkerboard/ // build a 6x6 checkerboard with alternate black and white colors. func Checkerboard(w http.ResponseWriter, r *http.Request) { size := size(r) m := image.NewRGBA(image.Rect(0, 0, size, size)) color1 := color.RGBA{uint8(255), uint8(255), 255, 255} Loading @@ -38,3 +39,17 @@ func H6X6(w http.ResponseWriter, r *http.Request) { var img image.Image = m write.Image(w, &img) } // extract size from HTTP request and return it. func size(r *http.Request) int { strSize := r.FormValue("size") if len(strSize) > 0 { if size, errSize := strconv.ParseInt(strSize, 0, 64); errSize == nil { isize := int(size) if isize > 0 && isize < 1000 { return int(size) } } } return 240 }
controllers/grid/random.go→controllers/squares/random.go +1 −1 Original line number Diff line number Diff line package grid package squares import ( "github.com/taironas/tinygraphs/colors" Loading
controllers/grid/square.go→controllers/squares/square.go +7 −4 Original line number Diff line number Diff line package grid package squares import ( "crypto/md5" Loading @@ -16,7 +16,7 @@ import ( "strings" ) // Square is the handler for /square/[A-Za-z0-9]+/? // Square is the handler for /squares/[A-Za-z0-9]+/? // build a 6x6 grid with alternate colors based on the number passed in the url func Square(w http.ResponseWriter, r *http.Request) { Loading Loading @@ -57,9 +57,9 @@ func Square(w http.ResponseWriter, r *http.Request) { } } // gridColorHandler is the handler for /square/[0-8]/[a-zA-Z0-9]+/? // Color is the handler for /square/[0-8]/[a-zA-Z0-9]+/? // build a 6x6 grid with alternate colors based on the number passed in the url func SquareColor(w http.ResponseWriter, r *http.Request) { func Color(w http.ResponseWriter, r *http.Request) { if colorId, err := misc.PermalinkID(r, 2); err != nil { log.Printf("error when extracting permalink id: %v", err) Loading Loading @@ -95,6 +95,7 @@ func SquareColor(w http.ResponseWriter, r *http.Request) { } } // extract hexadecimal code background from HTTP request and return color.RGBA func background(req *http.Request) (color.RGBA, error) { bg := req.FormValue("bg") if len(bg) == 0 { Loading @@ -104,6 +105,7 @@ func background(req *http.Request) (color.RGBA, error) { return color.RGBA{uint8(r), uint8(g), uint8(b), uint8(255)}, err } // extract hexadecimal code foreground from HTTP request and return color.RGBA func foreground(req *http.Request) (color.RGBA, error) { fg := req.FormValue("fg") if len(fg) == 0 { Loading Loading @@ -131,6 +133,7 @@ func hexToRGB(h string) (uint8, uint8, uint8, error) { return 0, 0, 0, nil } // extract size from HTTP request and return it. func size(r *http.Request) int { strSize := r.FormValue("size") if len(strSize) > 0 { Loading