This file contains hidden or 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 TestListRepos(t *testing.T) { | |
| teardown := setup() | |
| defer teardown() | |
| mux.HandleFunc("/orgs/octokit/repos", func(w http.ResponseWriter, r *http.Request) { | |
| w.Header().Set("Content-Type", "application/json") | |
| w.WriteHeader(http.StatusOK) | |
| // ... return the JSON | |
| }) | |
This file contains hidden or 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 api | |
| var ( | |
| mux *http.ServeMux | |
| server *httptest.Server | |
| client *Client | |
| ) | |
| func setup() func() { | |
| mux = http.NewServeMux() |
This file contains hidden or 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
| // Option is a functional option for configuring the API client | |
| type Option func(*Client) error | |
| // BaseURL allows overriding of API client baseURL for testing | |
| func BaseURL(baseURL string) Option { | |
| return func(c *Client) error { | |
| c.baseURL = baseURL | |
| return nil | |
| } | |
| } |
This file contains hidden or 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
| const apiURL = "https://api.github.com/" | |
| // Client holds information necessary to make a request to your API | |
| type Client struct { | |
| baseURL string | |
| httpClient *http.Client | |
| } | |
| // New creates a new API client | |
| func New() (*Client, error) { |
This file contains hidden or 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
| $ ./go-trace --help | |
| Usage of ./go-trace: | |
| -aperture float | |
| camera aperture (default 0.01) | |
| -fov float | |
| vertical field of view (degrees) (default 75) | |
| -height int | |
| height of image (default 500) | |
| -out string | |
| output filename (default "out.ppm") |
This file contains hidden or 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
| // inside the render function in main.go | |
| // create the ticker to tick every 100 milliseconds | |
| ticker := time.NewTicker(time.Millisecond * 100) | |
| // ... | |
| // create an anonymous goroutine to consume from the channel | |
| // and print after each tick | |
| go func() { |
This file contains hidden or 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
| start := time.Now() | |
| // .. some long running operation | |
| fmt.Printf("\nDone.\nElapsed: %v\n", time.Since(start)) |
This file contains hidden or 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 primitives | |
| type Metal struct { | |
| C Vector | |
| Fuzz float64 | |
| } | |
| func (m Metal) Bounce(input Ray, hit Hit) (bool, Ray) { | |
| direction := reflect(input.Direction, hit.Normal) | |
| fuzzed := VectorInUnitSphere().MultiplyScalar(m.Fuzz)) |
This file contains hidden or 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 primitives | |
| type Metal struct { | |
| C Vector | |
| } | |
| func (m Metal) Bounce(input Ray, hit Hit) (bool, Ray) { | |
| direction := reflect(input.Direction, hit.Normal) | |
| bouncedRay := Ray{hit.Point, direction} | |
| bounced := direction.Dot(hit.Normal) > 0 |
This file contains hidden or 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 color(r p.Ray, world p.Hitable, depth int) p.Vector { | |
| hit, record := world.Hit(r, 0.001, math.MaxFloat64) | |
| if hit { | |
| if depth < 50 { | |
| bounced, bouncedRay := record.Bounce(r, record) | |
| if bounced { | |
| newColor := color(bouncedRay, world, depth+1) | |
| return record.Material.Color().Multiply(newColor) | |
| } |