Article
Postgres logging
Before I forget let me write this down here. $$ log_stament - none - all
log_min_duration_statment - millisecond value
When you set log_statement=none and log_min_duration_statement=1 then any statement which takes longer than 1 millisecond will be logged.
When you set log_statement=all and log_min_duration_statement=1 then all statements are logged; however it only shows duration on statements longer than 1 millisecond.
Article
IC to EM
Last week, I got promoted to Engineering Manager (EM) of the Database team at Cloudflare. I joined the team almost 3 years ago. A senior team member and myself were hired to form a then dedicated database team. I have been enjoying it and the team is amazing to work with. Great people. Opportunities came to either advance on the Individual Contributor (IC) or the leadership side. I picked the latter.
Article
Context in go
context is a standard package. Context is an interface in context package.
type Context interface { Deadline() (deadline time.Time, ok bool) Done() <-chan struct{} Err() error Value(key interface{}) interface{} } There are 4 methods in Context interface. Most of the times, we don’t define our own types which satisfy the interface (which off course we can do), but we mostly use the factory functions provided by the context package itself.
Article
Closure in go
closure is a function inside another function where you can reference variable defined in the outer function.
I have seen them useful in dealing with packages where a function expects an type func() as an argument where the func() doesn’t take any argument.
example from package github.com/cenkalti/backoff
signature of backoff.Retry is as below
backoff.Retry(o backoff.Operation, b backoff.Backoff) where backoff.Operation is of type func() error
type Operation func() error func main() { func retryWrapper(imp string) func() error{ return func() { funcThatCouldFail(imp) retun nil } } err := backoff.
Article
defer statement in go
defer is one of the unique keywords in Go.
What does defer do? As the name suggests, it defers something. It defers function calls. A deferred function gets invoked right after the surrounding function returns.
func outer() { defer inner() log.Println("outer got called") } func inner() { log.Println("inner got called") } outer got called prints first then inner got called.
What the main use of defer statement? It helps mainly with actions that need to happen but not immediately.
Article
Notes on concurreny in Golang
Concurrency channels are like typed pipes, Where you can send something from one side and receive from other side. using channel direction operator <-. Depends on the direction of the variables around the operator, its either sending or receiving. x := <-c // receive from c c <- sum // send sum to c fmt.Println(“channel receive happening”, <-c) channels are reference type. similar to maps. So when we pass channel as an argument to a function or copy we are passing the reference.