It's been 3 months since I wrote my first Line of Code in Golang.
My Journey from PHP to Go
Boris Jam...
For further actions, you may consider blocking this person and/or reporting abuse
Hi Boris, happy you're liking Go so far!
I think the best solution is validation. I used govalidator successfully in a project.
You can do stuff like:
It took me a while to get testing right in my first project but Go has really powerful testing chops. I'm starting to like test tables and you can easily debug test cases from VSCode.
testify seems nice, haven't tried it yet
A couple of posts about unit testing in Go that I read:
There are resources around, you just have to find them. A good place to start are the newsletters Golang Weekly and Master the World of Golang.
Ah ah yes. Naming it Go was a bad move, it's too late for that
Have fun!
They should've just called it Gopher, like GopherCon right?
I will have a look at govalidator.
I already use testify for assertions, but it's not designed for mocking.
Thanks for your support, I'll have a look at your resources!
What about this part of testify's documentation? github.com/stretchr/testify#mock-p...
It doesn't work?
I didn't know about mocking with testify. It seems to be working similarly to gomock.
The problem is that the mocks have to be generated manually and to be maintained along with your codebase.
Yeah, fortunately I don't use mocking that much
This is the best article for Go I read because it comes from the person who is native in PHP. Awesome work Boris!
I appreciate your focus on tests; it helps me understand mocking in Go. Please continue to write about your from PHP to GO transition. I’m really curious about that.
Thank you so much, I'm very happy that you found it useful!
It is beneficial to me, since I am also thinking to start learning Go. Not necessary to be my primary language, I first want to understand the concept.
Use pointers!
Imagine the following:
then try to unmarshal this:
{ "Age": 30 }
You will get this:
if a key is missing, it's a simple nil check away.
Another nice technique I like to use is as follows:
Declare an
ok
interface:Implement it on your type:
Then simply:
You can see the full example in the go playground:
play.golang.org/p/P_88niVqOke
For me, the reading the body of request (or response in case of HTTP client) is not a big deal. You can easily define helper function that read all Body, create a new io.Reader then return read Body as bytes array.
For me (and also for Go maintener net/http Brad Fitzpatrick), HTTP client has to be improved (c.f. github.com/bradfitz/exp-httpclient) and will be.
Hi Jérôme, it's fun to see you here on dev.to!
What's the weather like in caen?
What you suggest with creating an io.Reader proves what I said above : many trivial things in popular languages can become complicated in Go.
cloudy ...
Maybe, but many complicated things in popular languages become trivial in Go ;) (Concurency, very good performance on tiny configuration, async task without tuning your thread pool, deploy on "From Scratch" docker's image and so on).
You can use pointer so missing value would be nil
It's a good idea, thanks!