标签:printf with console turn -- add ret scan format
以一个简单的例子说明一下go中比较有用的小工具
jeffreyguan@localhost ~$ cat > main.go
package main
import "fmt"
func main() { fmt.Println("Hello, Jeffrey Guan") }
jeffreyguan@localhost ~$ cat main.go 130 ?
package main
import "fmt"
func main() { fmt.Println("Hello, Jeffrey Guan") }
jeffreyguan@localhost ~$ gofmt main.go
package main
import "fmt"
func main() { fmt.Println("Hello, Jeffrey Guan") }
jeffreyguan@localhost ~$ gofmt -d main.go
diff -u main.go.orig main.go
--- main.go.orig 2019-08-17 21:42:13.000000000 +0800
+++ main.go 2019-08-17 21:42:13.000000000 +0800
@@ -1,5 +1,5 @@
package main
-import "fmt"
-func main() { fmt.Println("Hello, Jeffrey Guan") }
+import "fmt"
+func main() { fmt.Println("Hello, Jeffrey Guan") }
jeffreyguan@localhost ~$ gofmt -w main.go
jeffreyguan@localhost ~$ cat main.go
package main
import "fmt"
func main() { fmt.Println("Hello, Jeffrey Guan") }
jeffreyguan@localhost ~$ go build main.go
jeffreyguan@localhost ~$ file main
main: Mach-O 64-bit executable x86_64
按平台生成可执行文件
jeffreyguan@localhost ~$ GOOS=windows go build main.go
jeffreyguan@localhost ~$ file main.exe
main.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows
go get github.com/golang/example/hello
jeffreyguan@localhost ~/lanjie$ cat main.go
// demo is also demo
package main
import "fmt"
func main() { fmt.Println("Hello, Jeffrey Guan") }
jeffreyguan@localhost ~/lanjie$ go list -f '{{ .Name }}'
main
jeffreyguan@localhost ~/lanjie$ go list -f '{{ .Name }}: {{ .Doc}}'
main: demo is also demo
jeffreyguan@localhost ~/lanjie$ go list -f '{{ .Name }}: {{ .Doc}}'
main: demo is also demo
jeffreyguan@localhost ~/lanjie$ go list -f '{{ .Imports }}'
[fmt]
jeffreyguan@localhost ~/lanjie$ go list -f '{{ join .Imports "\n"}}' fmt
errors
internal/fmtsort
io
math
os
reflect
strconv
sync
unicode/utf8
jeffreyguan@localhost ~/lanjie$ go list -f '{{ .Doc }}' fmt
Package fmt implements formatted I/O with functions analogous to C's printf and scanf.
jeffreyguan@localhost ~/lanjie$ go doc fmt
jeffreyguan@localhost ~/lanjie$ go doc 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.
# 在本地启动go doc
jeffreyguan@localhost ~/lanjie$ godoc -http=localhost:6060
标签:printf with console turn -- add ret scan format
原文地址:https://www.cnblogs.com/double12gzh/p/11370825.html