This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "8d784442c57fa1647259a37c277c6738b2d79d6a", | |
"images": [ | |
"artwork/010-Body/blue_gopher.png", | |
"artwork/020-Eyes/crazy_eyes.png", | |
"artwork/024-Glasses/all_black_sunglasses.png", | |
"artwork/027-Extras/laptop.png" | |
], | |
"original_url": "https://storage.googleapis.com/gopherizeme.appspot.com/gophers/8d784442c57fa1647259a37c277c6738b2d79d6a.png", | |
"url": "https://lh3.googleusercontent.com/dnKffPVPSYSIXhelVR8q88IM2tHxTQ8GgxlCezQjjqLrGvQI9roQIF71NfaOYN5m3txAfbpzyA48nklQMTZ5wgvG", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ArtworkResponse struct { | |
Categories []Category `json:"categories"` | |
TotalCombinations int `json:"total_combinations"` | |
} | |
type Category struct { | |
ID string `json:"id"` | |
Name string `json:"name"` | |
Images []Image `json:"images"` | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"categories": [{ | |
"id": "artwork/010-Body", | |
"name": "Body", | |
"images": [{ | |
"id": "artwork/010-Body/blue_gopher.png", | |
"name": "blue gopher", | |
"href": "https://storage.googleapis.com/gopherizeme.appspot.com/artwork/010-Body/blue_gopher.png", | |
"thumbnail_href": "https://lh3.googleusercontent.com/2WSrI5x6u8LqWQ-xBzogIu3QrthPiawLH2zCPvrOgpMPU0K240di8pOKSwhz_IL0xiq5I2pBJkWrhyZDJeAPWD4=s71" | |
}, { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func handleGreeter() http.Handler { | |
// TODO: do any setup stuff here | |
//... like prepare a template: | |
tpl, err := template.ParseFiles("pages/_layout.html", "pages/gopher.html") | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
if err != nil { | |
// parsing the template failed? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sending | |
// AUTOGENERATED BY MOQ - DO NOT EDIT | |
// github.com/matryer/moq | |
import ( | |
"sync" | |
) | |
var ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
ctx := context.Background() | |
// trap Ctrl+C and call cancel on the context | |
ctx, cancel := context.WithCancel(ctx) | |
c := make(chan os.Signal, 1) | |
signal.Notify(c, os.Interrupt) | |
defer func() { | |
signal.Stop(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"log" | |
"os" | |
"os/exec" | |
) | |
type result struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am matryer on github. | |
* I am matryer (https://keybase.io/matryer) on keybase. | |
* I have a public key ASCC8YrsmU_t9rWCOgUqUGE0Zv9wb519A25FyiDH7xMXfAo | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestPathParams(t *testing.T) { | |
r, err := http.NewRequest("GET", "1/2/3/4/5", nil) | |
if err != nil { | |
t.Errorf("NewRequest: %s", err) | |
} | |
params := pathParams(r, "one/two/three/four") | |
if len(params) != 4 { | |
t.Errorf("expected 4 params but got %d: %v", len(params), params) | |
} | |
for k, v := range map[string]string{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pathParams parses the URL.Path of the Request with the given | |
// pattern, and extracts the value for each segment into a map. | |
func pathParams(r *http.Request, pattern string) map[string]string { | |
params := map[string]string{} | |
pathSegs := strings.Split(strings.Trim(r.URL.Path, "/"), "/") | |
for i, seg := range strings.Split(strings.Trim(pattern, "/"), "/") { | |
if i > len(pathSegs)-1 { | |
return params | |
} | |
params[seg] = pathSegs[i] |