0

SaveRequest メソッドを使用してhttp.Request、おそらく、それを (現在はパスのみで) postgres データベースに保存します。

func (logger *PostgresLogger) SaveRequest(req *http.Request) {
  os.Stdout.Write([]byte("Saving to PGDB\n"))
  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\n", Id)))

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

これは、 Hood構成ファイルdbConnectionをロードすることから得られます。

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 }
}

涼しい。そのため、リバース プロキシを起動して受信リクエストを保存するように依頼すると、次のように表示されます (ログの先頭に 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

そのため、Save から返される ID がインクリメントされていることがわかりますが、logging_development データベースを調べたところ、レコードがありません。

サーバーを停止して再起動すると、中断したところからIDが増加し続けるため、実際には保存されているように見えますが、どこで?

アップデート

開発構成は次のとおりです。

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

そして、PGAdmin が接続に対して表示するものの一部:

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    

編集:間違ったエラーをチェックするバグを修正しました(問題の原因ではありません)

4

1 に答える 1