Queuing problem using localhost storing lookup table?

(Sibert) #1

I am trying to create a lookup table of sql queries using Go and Postgresql. This is an unorthodox way to solve the problem with many queries, so it might be the wrong direction.

The code below works as expected for a few calling computers, but as every call ends up in ONE single session in the lookup database, I am wondering if this may cause future problem with queuing the lookups.

This is a followup question from REST API with 1000 query templates

I have setup a test server for only two lookups:

package main

import (
    _ "github.com/lib/pq"

var db *sql.DB
var err error

func main() {
    http.HandleFunc("/", Query)
    log.Fatal(http.ListenAndServe(":8080", nil))

func Connect() {
  const (
     host = ""
     port = 5432
     user = "go"
     password = "test"
     dbname  = "lookup")

  login := fmt.Sprintf("host=%s port=%d user=%s "+
    "password=%s dbname=%s sslmode=disable",
    host, port, user, password, dbname)

  var err error
    db, err = sql.Open("postgres", login)
    if err != nil {
    err = db.Ping()
    if err != nil {

func Query (w http.ResponseWriter, r *http.Request){
  id := strings.Replace(r.URL.String(), "/", "", -1) //remove slashes
  values := []string{"SELECT sqlx FROM get WHERE id =","'",id,"'"}
  query := strings.Join(values, "")
  var sqlx string
  var row *sql.Row

  row = db.QueryRow(query)
  err := row.Scan(&sqlx)

  if err != nil && err != sql.ErrNoRows {

  fmt.Fprintf(w,"%s", sqlx)