package main import ( "github.com/tsuru/tsuru.app" "log" "net/http" ) func main() { router := app.NewRouter() router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, World!")) }) log.Fatal(http.ListenAndServe(":8080", router)) }
package main import ( "github.com/tsuru/tsuru.app" "database/sql" _ "github.com/lib/pq" "log" ) func main() { db, err := sql.Open("postgres", "postgresql://user:password@localhost/dbname?sslmode=disable") if err != nil { log.Fatal(err) } err = db.Ping() if err != nil { log.Fatal(err) } rows, err := db.Query("SELECT * FROM users") if err != nil { log.Fatal(err) } defer rows.Close() for rows.Next() { // handle rows } }In this example, we connect to a PostgreSQL database using `sql.Open()`, ping the database to ensure we have a connection, and then perform a select query on the "users" table and iterate through the rows using `db.Query()` and `rows.Next()`. We use the `defer` keyword to close the `rows` variable once we have finished iterating.