Skip to content

[khanhkid] update assignment week5#10

Open
khanhkid wants to merge 2 commits intohavinhdat:masterfrom
khanhkid:master
Open

[khanhkid] update assignment week5#10
khanhkid wants to merge 2 commits intohavinhdat:masterfrom
khanhkid:master

Conversation

@khanhkid
Copy link
Copy Markdown

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,

getCommentsEndpoint = "https://my-json-server.typicode.com/typicode/demo/comments"
)

func HandleFunc(writer http.ResponseWriter, request *http.Request, isJSON bool) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: definition?

Comment thread dataloader/dataloader.go
data interfaces.LoadData
}

func (service *SeviceLoader) GetPosts() ([]defination.Post, error) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: this function does 2 things (get data and rendering), so can be separated into 2 smaller functions for readability

Comment thread dataloader/renderdata.go
data interfaces.RenderData
}

func (service *RenderServiceLoader) Render(writer http.ResponseWriter, postWithComment defination.PostWithCommentsResponse, isJSON bool) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: this function does 2 things (render json or render xml), so can be separated into 2 smaller functions for readability

Comment thread main.go
scanner := bufio.NewScanner(os.Stdin)
var isJSON bool
for scanner.Scan() {
text := scanner.Text()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants