...

Source file src/github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres/hook_test.go

Documentation: github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres

     1  // Copyright 2017 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  // Package postgres_test contains an example on how to use cloudsqlpostgres dialer
    15  package postgres_test
    16  
    17  import (
    18  	"database/sql"
    19  	"fmt"
    20  	"log"
    21  	"time"
    22  
    23  	_ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres"
    24  )
    25  
    26  // Example shows how to use cloudsqlpostgres dialer
    27  func Example() {
    28  	// Note that sslmode=disable is required it does not mean that the connection
    29  	// is unencrypted. All connections via the proxy are completely encrypted.
    30  	db, err := sql.Open("cloudsqlpostgres", "host=project:region:instance user=postgres dbname=postgres password=password sslmode=disable")
    31  	if err != nil {
    32  		log.Fatal(err)
    33  	}
    34  	defer db.Close()
    35  	var now time.Time
    36  	fmt.Println(db.QueryRow("SELECT NOW()").Scan(&now))
    37  	fmt.Println(now)
    38  }
    39  

View as plain text