Go to file
jordi fita mas 3d3221e202 Return HTTP 404 instead of 500 for invalid UUID values in URL
Since most of PL/pgSQL functions accept a `uuid` domain, we get an error
if the value is not valid, forcing us to return an HTTP 500, as we
can not detect that the error was due to that.

Instead, i now validate that the slug is indeed a valid UUID before
attempting to send it to the database, returning the correct HTTP error
code and avoiding useless calls to the database.

I based the validation function of Parse() from Google’s uuid package[0]
because this function is an order or magnitude faster in benchmarks:

  goos: linux
  goarch: amd64
  pkg: dev.tandem.ws/tandem/numerus/pkg
  cpu: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  BenchmarkValidUuid-4            36946050                29.37 ns/op
  BenchmarkValidUuid_Re-4          3633169               306.70 ns/op

The regular expression used for the benchmark was:

  var re = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")

And the input parameter for both functions was the following valid UUID,
because most of the time the passed UUID will be valid:

  "f47ac10b-58cc-0372-8567-0e02b2c3d479"

I did not use the uuid package, even though it is in Debian’s
repository, because i only need to check whether the value is valid,
not convert it to a byte array.  As far as i know, that package can not
do that.

[0]: tandem/tandem#40
2023-07-17 11:46:11 +02:00
cmd/numerus Implement login cookie, its verification, and logout 2023-01-17 20:58:13 +01:00
debian Add the customer name to the invoice’s PDF file name 2023-07-07 11:34:34 +02:00
demo Add empty IBAN and BIC to demo contacts 2023-07-02 02:26:35 +02:00
deploy Compute the total amount, base plus taxes, of all expenses 2023-07-13 20:50:26 +02:00
pkg Return HTTP 404 instead of 500 for invalid UUID values in URL 2023-07-17 11:46:11 +02:00
po Add reset button to filters 2023-07-16 20:56:11 +02:00
revert Compute the total amount, base plus taxes, of all expenses 2023-07-13 20:50:26 +02:00
test Compute the total amount, base plus taxes, of all expenses 2023-07-13 20:50:26 +02:00
verify Compute the total amount, base plus taxes, of all expenses 2023-07-13 20:50:26 +02:00
web Add reset button to filters 2023-07-16 20:56:11 +02:00
.gitignore Ignore IntelliJ’s project files 2023-01-30 16:42:15 +01:00
COPYING Rename LICENSE to COPYING 2023-01-15 04:08:35 +01:00
Makefile Rename extension of templates to .gohtml 2023-01-30 16:48:21 +01:00
go.mod Add the customer name to the invoice’s PDF file name 2023-07-07 11:34:34 +02:00
go.sum Add the customer name to the invoice’s PDF file name 2023-07-07 11:34:34 +02:00
sqitch.conf Setup authentication schema and user relation 2023-01-13 20:30:21 +01:00
sqitch.plan Compute the total amount, base plus taxes, of all expenses 2023-07-13 20:50:26 +02:00