Skip to content

Writing the code to reuse #1896

Answered by aldas
sriramkp asked this question in Q&A
Jun 15, 2021 · 2 comments · 5 replies
Discussion options

You must be logged in to vote

This is my personal opinion and may not be shared by others.

using binding payload directly to object is asking for problems. For example if you are using JSON and introduce new (public) field in your struct that is not meant to be unmarshaled to you could have attacker providing that field and therefore filling it with unwanted data.

This is probably overkill for small applications but I tend to create controllerlike structs that take dependencies from constructor so I do not need to use global instances and therefore can test/mock stuff more easily

For example for HTTP layer

type HTTPHandlers struct {
	db DB // in my own code a service for that domain.
}

func RegisterPromoAreaHandlers(p…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@sriramkp
Comment options

@aldas
Comment options

@sriramkp
Comment options

@sriramkp
Comment options

@aldas
Comment options

Answer selected by sriramkp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants