Error: package command-line-arguments is not a main package

I’m new in Go programming and I recently while following “Introducing Go by Caleb” I encountered with this error message package command-line-arguments is not a main package

Here’s the code I was trying to run -

package ammar

import "fmt"

func main() {

    fmt.Println(true && true)

    fmt.Println(true && false)

    fmt.Println(true || true)

    fmt.Println(true || false)

    fmt.Println(!true)

}

Would be grateful if someone provides a solution? Thanks!

1 Like

The errors tells your what the problem is.

Your code is not a package named “main”. Use package main as first line instead.

3 Likes

Thanks! Can my package name be anything or it always needs to be main? And Does my package name and function name should be same?

The package name can be an arbitrary identifier, though if you want a package to serve as an entry point for an executable program, it needs to be named “main” and have a function main() with no arguments and no return type.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.