package main import ( "errors" "time" ) type LeanworkIn struct { Id int64 PickupUrl string ReceiveUrl string SignType string OrderNo string OrderAmount string OrderCurrency string CustomerId string Sign string Valid bool Ts time.Time Ip4 uint32 Ip4Location string MD5Key string } // func lrIsIdMatchSign(id string, sign string) bool { _, err := getRequestRowByIdAndSign(id, sign) return err == nil } func getLeanworkInById(id int64) (row LeanworkIn, err error) { db.conn(Config) defer db.close() err = db.h.QueryRow("SELECT * FROM leanworkIn WHERE id=? ", id).Scan( &row.Id, &row.PickupUrl, &row.ReceiveUrl, &row.SignType, &row.OrderNo, &row.OrderAmount, &row.OrderCurrency, &row.CustomerId, &row.Sign, &row.Valid, &row.Ts, &row.Ip4, &row.Ip4Location, &row.MD5Key) return } func getRequestRowByIdAndSign(id string, sign string) (row LeanworkIn, err error) { //retrieve form DB db.conn(Config) defer db.close() selDB, err := db.h.Query("SELECT * FROM leanworkIn WHERE id=? and sign=?", id, sign) if err != nil { return } count := 0 for selDB.Next() { err = selDB.Scan(&row.Id, &row.PickupUrl, &row.ReceiveUrl, &row.SignType, &row.OrderNo, &row.OrderAmount, &row.OrderCurrency, &row.CustomerId, &row.Sign, &row.Valid, &row.Ts, &row.Ip4, &row.Ip4Location, &row.MD5Key) if err != nil { return } count++ } if count <= 0 { err = errors.New("no record found by the given id (" + id + ") and sign(" + sign + ")") } return }