Hacker News new | ask | show | jobs
by justicezyx 2022 days ago
``` package main

import ( "fmt" "log" "net/http" )

func init() { setupDBConnection(dbName) }

func handler(w http.ResponseWriter, r *http.Request) {

    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func main() { fmt.Println("Processing your serverless request") http.HandleFunc("/", handler) log.Fatal(http.ListenAndServe(":8080", nil)) }

```

This code snippet is an example of "Run bootstrapping logic once, and reuse it across Min Instances".

Assuming the boostrapping logic refers to the `init()` function that connects to DB. Does Cloud Run looks for init() in a Golang app to invoke?

I cannot seem follow the code's logic and its connection with the stated purpose.

Did I miss anything?

1 comments