DEV Community

Andy Yang
Andy Yang

Posted on

Release 0.1 review

Release 0.1 review

Finding someone to work with is easy, I posted a link on the slack channel.
I was amazed that there are several people working on Golang.

To work with others' code, I found some different ways to do the same job. Actually, I enjoy reading others' code and excited when I found some improvements. Waiting for Someone reviewing my code is amazing too. It helps me to be a better programmer.

The issues I found.

Add go module support to the project, so the source code can be put on anywhere(not only inside GOPATH).

After extract the links from the file, there are duplicate link in the array. I added a function to remove the duplicate links.

// remove duplicate strings from a slice of strings
func removeDuplicate(urls []string) []string {
    result := make([]string, 0, len(urls))
    temp := map[string]struct{}{}
    for _, item := range urls {
        if _, ok := temp[item]; !ok {
            temp[item] = struct{}{}
            result = append(result, item)
        }
    }
    return result
}
Enter fullscreen mode Exit fullscreen mode

The for loop in Go is a little bit tricky, I found a tricky way to improve the for loop.

i := 0
for i < len(links) {
    ls := <-channel
    if ls.GetLiveStatus() == false {
        downLinks = append(downLinks, ls.GetURL())
    } else {
        upLinks = append(upLinks, ls.GetURL())
    }
    i++
}
// After
for range links {
    ls := <-channel
    if ls.GetLiveStatus() == false {
        downLinks = append(downLinks, ls.GetURL())
    } else {
        upLinks = append(upLinks, ls.GetURL())
    }
}
Enter fullscreen mode Exit fullscreen mode

Issues on my repo

Some typos are fixed.

// before
if *version == true {}

// after
if *version {}
Enter fullscreen mode Exit fullscreen mode

Found an issue is harder than fixed the issue. The open-source world is fun to work with.

Top comments (0)