Go/Quick Start: Difference between revisions

From Fundamental Ramen
< Go
Jump to navigation Jump to search
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Create a module =
= Create a module =
Create module and source file.
<syntaxhighlight lang="bash">
go mod init sandbox/hello
touch hello.go
</syntaxhighlight>
Add source code.


<syntaxhighlight lang="go">
<syntaxhighlight lang="go">
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
</syntaxhighlight>
</syntaxhighlight>


= Run =
Run.
 
<syntaxhighlight lang="bash">
go run .
</syntaxhighlight>
 
= Work with 2 modules =
 
<syntaxhighlight lang="bash">
mkdir main greetings sucks
cd greetings
go mod init sandbox/greetings
cd ../sucks
go mod init sandbox/sucks
cd ../main
go mod init
go mod edit -replace sandbox/greetings=../greetings
go mod edit -replace sandbox/sucks=../sucks
go mod tidy
</syntaxhighlight>

Latest revision as of 02:57, 22 May 2025

Create a module

Create module and source file.

go mod init sandbox/hello
touch hello.go

Add source code.

package main

import "fmt"

func main() {
	fmt.Println("Hello, World!")
}

Run.

go run .

Work with 2 modules

mkdir main greetings sucks
cd greetings
go mod init sandbox/greetings
cd ../sucks
go mod init sandbox/sucks
cd ../main
go mod init
go mod edit -replace sandbox/greetings=../greetings
go mod edit -replace sandbox/sucks=../sucks
go mod tidy