Grokking Advanced Go
0% completed
Capstone: HTTP API and Errors
A client creates an order and includes "paid":true in the body. What should the service do? It could accept the field, in which case anyone can receive goods without paying. It could ignore the field, in which case the client believes that the order is paid while the stored order is unpaid.
The third choice is to refuse the request with an error, and this service does that. The struct that receives a new order has no Paid field and no ID field, and the decoder rejects any member that the struct does not declare. The compiler and the decoder then enforce the rule together, with no `if
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%