Golang anatomy: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Project Structure | This page is a general getting started in go. | ||
= Project Structure = | |||
<blockquote> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
myproject/ | myproject/ | ||
Line 61: | Line 64: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | }} | ||
</blockquote><!-- Project Structure --> | |||
= Documentation = | |||
<blockquote> | |||
<syntaxhighlight lang="go"> | |||
go doc io | |||
</syntaxhighlight> | |||
</blockquote><!-- Documentation --> | |||
= Build = | |||
<blockquote> | |||
<syntaxhighlight lang="go"> | |||
# build/run main package | |||
go run . | |||
# test | |||
# build management | |||
go build | |||
go clean | |||
go install | |||
</syntaxhighlight> | |||
</blockquote><!-- Buidl --> |
Revision as of 01:31, 21 June 2022
This page is a general getting started in go.
Project Structure
myproject/ go.mod # module name, requirements main.go # optional CLI entrypoint printer.go # other 'main' package src are in toplevel dir internal/ # exported symbols from internal packages are only exposed within 'myproject' logger/ # subpackage logger.go math/ # subpackage division.go multiplication.gomyproject/go.mod
// myproject/go.mod module example.com/x/myproject go 1.18myproject/main.go
// myproject/main.go package main import ( "fmt" "example.com/x/myproject/internal/logger" ) func main() { logger.Info.Println("a log statement") fmt.Println("hello world") }myproject/internal/logger/logger.go
// myproject/internal/logger/logger.go package logger var Info *log.Logger func init() { Info = log.New(io.Stderr, "INFO: ", log.Ldate|log.Ltime|log.Llongfile) }
Documentation
go doc io
Build
# build/run main package go run . # test # build management go build go clean go install