How to Make godoc Command Works on Ubuntu/Mint

3616
Share:
how-to-make-godoc-command-works-on-ubuntu-mint

I was just started learning Go programming a week ago. I've read some books and decided to start coding and get used to it. Most of the time when I hit the wall, I'll do a quick search on it. With PHP, the PHP Manual has been my primary source. The comments below are treasure. As with Go, I believe it's godoc.

Not long after successfully installed Go on my Linux box and wrote some codes I get my first error. Here's my code:

package main

import "fmt"

func main() {
    fmt.Println('Hello there')
}

What I notice is: right after saving the file (I'm using Atom editor) it also check the code for error. In my case, it's:

Go Debug Error
./main.go:6:17: invalid character literal (more than one character)

 

I don't just trust the debugger, so I run the code:

$ go run hello.go
# command-line-arguments
src/main.go:6:17: invalid character literal (more than one character)

Wonderful. It has the same error as the debugger. Let's consult with godoc.

$ godoc fmt Println
bash: command not found: godoc

Well, it seems that I haven't installed the godoc package. Let's fix this.

$ sudo apt install golang-go.tools

After installation has finished, the command godoc fmt Println should be succeded:

$ godoc fmt Println
func Println(a ...interface{}) (n int, err error)
    Println formats using the default formats for its operands and writes to
    standard output. Spaces are always added between operands and a newline
    is appended. It returns the number of bytes written and any write error
    encountered.

OK, it's installed correctly and there's nothing mentioned "invalid character literal". A little disappointed, I then do a Google search and figure out that the cause was single quote. Single quote is used for 'rune', meanwhile 'string' should use double quotes.

Lessons Learned

There's nothing meaningless. This time I learned:

  • Go is great for a new language, it has offline documentation/manual.
  • Still, Googling could solve problem faster.
  • Throw away my PHP coding habit: using single quote and double quotes randomly.

I also hope that you now know how to make godoc command runs on Linux Mint/Ubuntu/Debian. If you run into any issues or have any feedback feel free to drop a comment below.

Tags
Share:

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *