dton37910 2013-05-11 23:34
浏览 1

将Hood存入Postgres,但不确定在哪里

I have a SaveRequest method that takes and http.Request and then, supposedly, saves it (right now just the path) to a postgres database:

func (logger *PostgresLogger) SaveRequest(req *http.Request) {
  os.Stdout.Write([]byte("Saving to PGDB
"))
  request := db.Requests { Path: req.URL.Path }
  transaction := logger.dbConnection.Begin()
  Id, saveError := transaction.Save(&request)
  if saveError != nil {
    panic(saveError)
  }

  os.Stdout.Write([]byte(fmt.Sprintf("%v
", Id)))

  transactionError := logger.dbConnection.Commit()
  if transactionError != nil {
    panic(transactionError)
  }
}

That dbConnection comes from loading a Hood config file:

func New(prefix string) (PostgresLogger) {
  dbConnection, err := hood.Load("/Users/ls/Dropbox/programming/go/src/postgres_logger/db/config.json", "development")
  if err != nil {
    panic(err)
  }

  return PostgresLogger{ prefix: prefix, dbConnection: dbConnection }
}

Cool. So when I start the reverse proxy and ask it to save incoming requests, I see this (sample, where logs are prefixed by RVSPRXY):

Saving to PGDB
56
RVSPRXY (1368315177148901322):
[::1]:51142 GET /css/editor.css

Saving to PGDB
RVSPRXY (1368315177149851787):
[::1]:51143 GET /js/handlebars.min.js

Saving to PGDB
RVSPRXY (1368315177150164615):
[::1]:51140 GET /css/mercury.bundle.css

Saving to PGDB
RVSPRXY (1368315177150358938):
[::1]:51141 GET /css/mercury_regions.bundle.css

Saving to PGDB
RVSPRXY (1368315177150776986):
[::1]:51144 GET /js/jquery-2.0.0.min.js

Saving to PGDB
57
58
59
60

So we can see it incrementing the id being returned from Save, but I look in the logging_development database and there are no records.

Stopping and restarting the server continues to increment the ids from where it left off, so it seems like it is actually saving, but where?

Update

Here is the development config:

{
   "development": {
     "driver": "postgres",
     "source": "user=logging dbname=logging_development sslmode=disable"
   }
 }

And some of what PGAdmin shows for connections:

5289    logging logging_development 2013-05-11 17:54:48.700467-06   127.0.0.1:51403 INSERT INTO "requests" ("path", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  
5290    logging logging_development 2013-05-11 17:54:48.746065-06   127.0.0.1:51414 INSERT INTO "requests" ("path", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  
5291    logging logging_development 2013-05-11 17:54:48.747876-06   127.0.0.1:51415 INSERT INTO "requests" ("path", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  
5292    logging logging_development 2013-05-11 17:54:48.748086-06   127.0.0.1:51416 INSERT INTO "requests" ("path", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  
5293    logging logging_development 2013-05-11 17:54:48.74866-06    

Edit: fixed a bug checking the wrong error (not the cause of the issue)

  • 写回答

1条回答 默认 最新

  • douti8321 2013-05-12 01:56
    关注

    You wrote:

    func (logger *PostgresLogger) SaveRequest(req *http.Request) {
        os.Stdout.Write([]byte("Saving to PGDB
    "))
        request := db.Requests{Path: req.URL.Path}
        transaction := logger.dbConnection.Begin()
        Id, saveError := transaction.Save(&request)
        if saveError != nil {
            panic(saveError)
        }
        os.Stdout.Write([]byte(fmt.Sprintf("%v
    ", Id)))
        transactionError := logger.dbConnection.Commit()
        if saveError != nil {
            panic(transactionError)
        }
    }
    

    What results do you get if you write:

    func (logger *PostgresLogger) SaveRequest(req *http.Request) {
        os.Stdout.Write([]byte("Saving to PGDB
    "))
        request := db.Requests{Path: req.URL.Path}
        transaction := logger.dbConnection.Begin()
        Id, saveError := transaction.Save(&request)
        if saveError != nil {
            panic(saveError)
        }
        os.Stdout.Write([]byte(fmt.Sprintf("%v
    ", Id)))
        // commit transaction
        transactionError := transaction.Commit()
        // check transactionError
        if transactionError != nil {
            panic(transactionError)
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口