Skip to content

Instantly share code, notes, and snippets.

View arschles's full-sized avatar
🎯
Focusing

Aaron Schlesinger arschles

🎯
Focusing
View GitHub Profile
@arschles
arschles / log_entry.go
Last active September 11, 2018 20:51
Threading Log Entries Down the Stack in Athens
func newLogEntry(req *http.Request, lggr *log.Logger) logrus.Entry {
return lggr.WithFields(logrus.Fields{
"http-method": req.Method,
"http-path": req.URL.Path,
"http-url": req.URL.String(),
})
}
@arschles
arschles / keep-cool-with-fans.go
Last active August 19, 2023 10:10
Fan-out and Fan-in with Go
package fans
// this code was inspired by https://talks.golang.org/2012/concurrency.slide#36
//
// it uses the context package (which wasn't available when that presentation was made) instead of a timer to
// do timeouts
import (
"context"
"time"
@arschles
arschles / more-resources.md
Last active January 13, 2023 15:44
Tuning an HTTP Client for Great Good!

Other Go Libraries to Help With Doing HTTP Clients

  • ctxhttp - use HTTP clients but do requests timeouts with a context
    • httptrace - a good library to pair with ctxhttp; you can use this to trace requests up to the server. this is pretty advanced usage, so I recommend you go here once you have basic performance issues sorted out
  • fasthttp - slightly easier-to-use HTTP client. you still have to deal with connection pool details though. still useful if you like the API better
  • go-cleanhttp - battle-tested HTTP client. useful to compare against the above code
  • gorequest - nicer API, not as geared toward load testing. recommend against this for load tests, but for business logic it's good
@arschles
arschles / athens-tests.sh
Created August 15, 2018 00:45
Running athens tests
#!/bin/sh
make dev-teardown
export GO_BINARY_PATH=go1.11rc1
make alldeps
# sleep a little more
sleep 5
buffalo db create
buffalo db migrate up
make test-unit
@arschles
arschles / buffalo_actions_test.go
Last active July 10, 2018 16:42
Sample Buffalo Test
package actions
// this is a test method. It needs to have the prefix "Test"
func (a *ActionSuite) TestSomething() {
// this gives you one of these: https://godoc.org/github.com/stretchr/testify/require#Assertions
//
// you can also use a.Assert() to get one of these: https://godoc.org/github.com/stretchr/testify/assert#Assertions
r := a.Require()
// this gets you a completely empty DB with all the schemas and migrations already run on it.
@arschles
arschles / demo.sh
Last active May 18, 2018 00:14
Cloud Native PDX May 17 2018 Demo Commands
#!/bin/bash
echo "OSBA (the broker for Azure) and service-catalog (the adapter for Kubernetes) are installed:"
helm list
echo "we also have a cool catalog of services we can create and hook up to:"
kubectl get clusterserviceclasses
echo "that's lame ... let's use svcat to see a friendly version:"
svcat get classes
@arschles
arschles / retro.md
Created August 16, 2017 16:38
SIG-Service-Catalog LGTM Policy Retro 8/17/2017

This PR was merged on July 19, 2017: kubernetes-retired/service-catalog#1050.

In the thread on that PR, both jdumars and I suggested that we try the change out and then have a retrospective on how that change has affected:

  1. Our ability to actively get a PR merged
  2. The quality of the project over the month of the LGTM policy as of this PR

I'll be facilitating an initial 15 minute retrospective.

If you have opinions on either of those topics, please bring them to present at this meeting. I am going to focus this discussion on opinions backed up with data that show trends over the 7/19 - 8/17 time frame.

@arschles
arschles / binding-finalizer.md
Last active December 7, 2016 21:20
Finalizer Example for Binding Objects
metadata:
  name: my-binding
  namespace: default
  finalizers:
    - kubernetes # a default
    - something.deis.io/a # custom
    - something.deis.io/b # custom
@arschles
arschles / for_select.go
Last active October 17, 2016 20:02
for/select loop for tickers & timers
i := 0
for {
select {
case <- timer.C:
return
case <-ticker.C:
fn(i)
i++
}
}
@arschles
arschles / chan-over-chan.go
Created September 9, 2016 20:52
Sending a channel over a channel
package main
import (
"log"
"time"
)
type acker struct {
ch chan time.Duration
}