top | item 23210213

(no title)

triztian | 5 years ago

Hey there I found modules to be confusing coming from GOPATH too, but they're straight forward, super barebones example:

    #!/bin/bash

    cd $HOME

    # Create project directory
    mkdir hellogo

    cd hellogo

    # Init project modfile
    go mod init example.com/hellogo

    # Create the main source file
    # Uses bash's heredoc
    cat << EOF > ./main.go
    package main
    import "fmt"
    func main() {
        fmt.Print("Hello world")
    }
    EOF

    # Build it
    go build

    # Run it
    ./hellogo

discuss

order

sk0g|5 years ago

You can also skip building, and run directly using `go run`!