Experienced developer but new to Go, what did I do wrong / right in my first package?

Written by
Link to Post

https://www.reddit.com/r/golang/comments/bnyrzp/experienced_developer_but_new_to_go_what_did_i_do/ by 

I have about 5 years of experience programming but mostly with higher level languages like javascript, PHP, and some Java. I’ve been really interested in learning Go so I decided to write a robots.txt parser to help me learn which can be found here. I don’t have anyone close to me that can give me good feedback on what “good” Go code would look like, so I’m posting here hoping experts can help me get better. I’m also new to posting to reddit so I apologize if this kind of “check out my work” post isn’t a good thing, but please let me know.

Some decisions I made along the way: * My package mainly exports an interface RobotsExclusionProtocol but returns the implementation and it’s methods as a value instead of a pointer. My understanding of when to use pointers vs. values is that you should use pointers if your going to mutate the struct during the method or if the struct is very large and would be costly to copy all over the place. * 2 of the main ways of creating an implementation of the RobotsExclusionProtocol is NewFromFile and NewFromURL (which does an HTTP request) functions, both of which take a channel so that you could use them with goroutines. The other method of creating an implementation is just a New function that does not use channels. I decided to use channels for NewFromFile and NewFromURL because from my experience with NodeJS, reading a file and doing an HTTP request are asynchronous operations, so I figured they should be here as well.

submitted by /u/itmayziii
[link] [comments]

Article Tags:
· ·
Article Categories:

Leave a Reply