[khanhkid] update assignment week5#10
Conversation
| getCommentsEndpoint = "https://my-json-server.typicode.com/typicode/demo/comments" | ||
| ) | ||
|
|
||
| func HandleFunc(writer http.ResponseWriter, request *http.Request, isJSON bool) { |
There was a problem hiding this comment.
this HandleFunc depends tightly with your defined dependency.
To apply DI further, you can create handerImpl struct that contain all dependencies that can be injected.
The separate dependency initialization out of logic/handler...
| "net/http" | ||
|
|
||
| "../dataloader" | ||
| "../defination" |
| data interfaces.LoadData | ||
| } | ||
|
|
||
| func (service *SeviceLoader) GetPosts() ([]defination.Post, error) { |
There was a problem hiding this comment.
Nitpick: this function does 2 things (get data and rendering), so can be separated into 2 smaller functions for readability
| data interfaces.RenderData | ||
| } | ||
|
|
||
| func (service *RenderServiceLoader) Render(writer http.ResponseWriter, postWithComment defination.PostWithCommentsResponse, isJSON bool) { |
There was a problem hiding this comment.
Nitpick: this function does 2 things (render json or render xml), so can be separated into 2 smaller functions for readability
| scanner := bufio.NewScanner(os.Stdin) | ||
| var isJSON bool | ||
| for scanner.Scan() { | ||
| text := scanner.Text() |
There was a problem hiding this comment.
It's nice that you're adding this part, but the code is now tightly coupled with input is Stdin.
We can make the program accept any input by DI.
Thank you for sharing your knowledge about Dependency Injection.
Im trying to learning and implement that in my project.
About Testing,
Im not yet understand how I can use Mockery in Golang, Golang is new language for me.
Im learning it by my self and I hope I can apply testing into this assignment later.
Thank you so much,