golang-echo-boilerplate
golang-echo-boilerplate copied to clipboard
Refactoring NewPostResponse
I don't think we need to use append() since we know the number of posts and append() just slows down the function.
Better to do so:
func NewPostResponse(posts []models.Post) *[]PostResponse {
postResponse := make([]PostResponse, len(posts))
for i, p := range posts {
postResponse[i] = PostResponse{
Title: p.Title,
Content: p.Content,
Username: p.User.Name,
ID: p.ID,
}
}
return &postResponse
}
Hello, it is a good idea. Please, create a PR to add this improvement.
not actual