func ValidateApiKey(db *sql.DB, apiKey string) (bool, error) {
	err := checkKeyFormat(apiKey)
	if err != nil {
		return false, fmt.Errorf("api key rejected: %s", err)
	}

	checkSQL := `UPDATE api_keys SET lastUsed = ? WHERE apiKey = ?`
	statement, err := db.Prepare(checkSQL)
	result, err := statement.Exec(time.Now().Format(time.RFC3339), apiKey)
	if err != nil {
		return false, fmt.Errorf("failed to update api key record in db: %s", err)
	}
	nRows, err := result.RowsAffected()

	return nRows == 1, err
}
// ValidateApiKey checks a given key against the keys table. Invalid keys are rejected.
ValidateApiKey checks a given key against the keys table. Invalid keys are rejected.
// ValidateApiKey checks a given key against the keys table . Invalid keys are rejected .
func ValidateApiKey(db *sql.DB, apiKey string) (bool, error) {
	err := checkKeyFormat(apiKey)
	if err != nil {
		return false, fmt.Errorf("api key rejected: %s", err)
	}
	checkSQL := `UPDATE api_keys SET lastUsed = ? WHERE apiKey = ?`
	statement, err := db.Prepare(checkSQL)
	result, err := statement.Exec(time.Now().Format(time.RFC3339), apiKey)
	if err != nil {
		return false, fmt.Errorf("failed to update api key record in db: %s", err)
	}
	nRows, err := result.RowsAffected()
	return nRows == 1, err
}
func ValidateApiKey ( db * sql . DB , apiKey string ) ( bool , error ) { err := checkKeyFormat ( apiKey ) if err != nil { return false , fmt . Errorf ( " " , err ) } checkSQL := `UPDATE api_keys SET lastUsed = ? WHERE apiKey = ?` statement , err := db . Prepare ( checkSQL ) result , err := statement . Exec ( time . Now ( ) . Format ( time . RFC3339 ) , apiKey ) if err != nil { return false , fmt . Errorf ( " " , err ) } nRows , err := result . RowsAffected ( ) return nRows == 1 , err }
ValidateApiKey checks a given key against the keys table.
ValidateApiKey checks a given key against the keys table .