mirror of
https://github.com/Pungyeon/clean-go-article.git
synced 2024-11-10 09:24:04 +00:00
Replace 'Option struct' with 'QueueOptions struct'
This commit is contained in:
parent
3ffc571622
commit
f5e46d1349
|
@ -385,7 +385,7 @@ q, err := ch.QueueDeclare(QueueOptions{
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
This solves two problems: misusing comments, and accidentally labeling the variables incorrectly. Of course, we can still confuse properties with the wrong value, but in these cases, it will be much easier to determine where our mistake lies within the code. The ordering of the properties also doesn't matter anymore, so incorrectly ordering the input values is no longer a concern. The last added bonus of this technique is that we can use our Option `struct` to infer the default values of our function's input parameters. When structures in Go are declared, all properties are initialised to their default value. This means that our `QueueDeclare` option can actually be invoked in the following way:
|
This solves two problems: misusing comments, and accidentally labeling the variables incorrectly. Of course, we can still confuse properties with the wrong value, but in these cases, it will be much easier to determine where our mistake lies within the code. The ordering of the properties also doesn't matter anymore, so incorrectly ordering the input values is no longer a concern. The last added bonus of this technique is that we can use our `QueueOptions` struct to infer the default values of our function's input parameters. When structures in Go are declared, all properties are initialised to their default value. This means that our `QueueDeclare` option can actually be invoked in the following way:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
q, err := ch.QueueDeclare(QueueOptions{
|
q, err := ch.QueueDeclare(QueueOptions{
|
||||||
|
|
Loading…
Reference in a new issue