title: Get dynamic sql in Golang
body: <p>I am trying to create a REST API in Golang. The problem is that I have more than 1000 complex SQL script that should be executed and fetched from the database.</p>
  
  <p>Is it possible to take the web address <em><code>/get/job/23</code></em> and dynamically grab the sql from a package, template or text document that basically contain text only = sql script? And then fire the prepare and execute in the <strong><em>main.go</em></strong>?</p>
  
  <p>It seems that importing 1000 packages and storing 1000 complex SQL statements in the <strong><em>main.go</em></strong> is sort of impossible.</p>
  
  <p>Here is a newbie pseudo code that shows what I am looking for:</p>
  
  <pre><code>package main
  
  import (
     "encoding/json"
     "log"
      "net/http"
      "database/sql"
      "github.com/gorilla/mux"
      _ "github.com/lib/pq"
  )
  
  func Getsql (dynamic path to script with parameter) returns (string)      
  
  /* The url /get/job/id is stored as a document/package/template       
  as "getjobid" = dynamic path based on url passed */
  
  func (db *DB) Conn(ctx context.Context) (*Conn, error)
  func (db *DB) Prepare(query string) (*Stmt, error)
  func (db *DB) Query(query string, args ...interface{}) (*Rows, err)
  
  func main() {
  http.HandleFunc("/", handler)
  log.Fatal(http.ListenAndServe(":8080", nil))
  }
  </code></pre>
  
  <p>Of course, I do not know if this is even possible, but I am thankful for pointing me in the right direction.</p>
  
  <p><strong>Added</strong></p>
  
  <p>I think of this as 4 problem to solve:</p>
  
  <ol>
  <li>How to store the plain sql in a document (template?) within Golang </li>
  <li>How to dynamically set the path to this document based on url.</li>
  <li>How to send parameters to a document (id)</li>
  <li>How to read the content and execute the sql</li>
  </ol>