Hot answers tagged

2

When it comes to "best practices" to mock interfaces, there's a number of things to consider, not in the least: ease of use. Over the years, I've taken to use a mock generator tool. Rather than just implementing the interface in question, GoMock supports a lot of other useful things. You can read more about it here. The way to use it in your case ...


2

This seems fine to me: it's nice and simple, and I've seen this pattern used "in the wild" before. One thing you could do is, in the MockUserRepo proxying functions, if the function variable is nil, either execute a default implementation, or return a more specific error (or even panic). For example: func (m *MockUserRepo) GetUserByEmail(s string) (...


2

Your code appears to fail on: Example 1: Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6]. Output: intervals : [[1 3] [2 6] [8 10] [15 18]] comparing intervals [1 3] and [2 6] comparing intervals [2 6] and [8 10] comparing intervals [8 10] and [...


1

String Constants An alternative way for representing your constants if you don't need their string representations would be to use the iota identifier built into golang to assign auto-incrementing enumerations like so: const ( Plus = iota // 0 Minus // 1 Number // 2 Skip // 3 Newline // 4 ) This is ...


1

A couple thoughts on contact.go. Global Variables In general, it's advised to not use global variables like var mailgunSender string = "email@sender.com" var mailgunReceiver string = "email@receiver.com" Instead, there are a few options. You already have a struct definition inside the HandleContact closure, so you could just move them ...


Only top voted, non community-wiki answers of a minimum length are eligible