Patterns

Good Resources

Testing code that uses goroutines

I’m using github.com/stretchr/testify/mock:

type SomeService struct {

}

func (ss *SomeService) SomeMethod(parameter string) {
	go doSomethingElse()
}

func doSomethingElse() {
  // some thing we want to do
}

type SomeServiceMock struct {
	mock.Mock
	wg sync.WaitGroup
}

func (ss *SomeServiceMock) SomeMethod(parameter string) {
	defer ss.wg.Done()
	ss.Called(parameter)
}

func TestSomething(t *testing.T) {
  someService := new(SomeServiceMock)
  someService.wg.Add(1)
  someService.On("SomeMethod", "someParameter").Return(nil).Times(1)

  // execute code that we want to test using the someService mock

  someService.wg.Wait()
  mock.AssertExpectationsForObjects(t, someService)
}

Convert float to string

s := fmt.Sprintf("%f", 123.456) // s == "123.456000"

Books

Cool Projects

Frameworks

ORM

Tools

Swagger on Go projects

Interesting Posts