2018年3月17日

1.12 配置文件读取

摘要: config.json go package main import ( "encoding/json" "fmt" "os" ) type Client struct { consulIP string connString string } func (c Client) String() st 阅读全文

posted @ 2018-03-17 23:16 cucy_to 阅读(118) 评论(0) 推荐(0) 编辑

1.11 程序优雅退出

摘要: ```go package main import ( "fmt" "io" "log" "os" "os/signal" "syscall" "time" ) var writer os.File func main() { // The file is opened as // a log fi 阅读全文

posted @ 2018-03-17 23:11 cucy_to 阅读(98) 评论(0) 推荐(0) 编辑

1.10 read.wirte from stdin stdout the child process

摘要: stdout 标准输入到标准输出 阅读全文

posted @ 2018-03-17 22:48 cucy_to 阅读(130) 评论(0) 推荐(0) 编辑

1.9 进程pid,运行耗时 运行退出状态

摘要: ```go package main import ( "fmt" "os/exec" "runtime" "time" ) func main() { var cmd string if runtime.GOOS == "windows" { cmd = "timeout" } else { cmd = "sleep" } proc := exec.Comman... 阅读全文

posted @ 2018-03-17 22:42 cucy_to 阅读(146) 评论(0) 推荐(0) 编辑

1.8 执行命令

摘要: 2 阅读全文

posted @ 2018-03-17 22:30 cucy_to 阅读(82) 评论(0) 推荐(0) 编辑

1.7获取os信号

摘要: ```go package main import ( "fmt" "os" "os/signal" "syscall" ) func main() { // Create the channel where the received // signal would be sent. The Not 阅读全文

posted @ 2018-03-17 22:22 cucy_to 阅读(120) 评论(0) 推荐(0) 编辑

1.6 获取程序运行的pid

摘要: ```go package main import ( "fmt" "os" "os/exec" "strconv" ) func main() { pid := os.Getpid() fmt.Printf("Process PID: %d \n\n", pid) prc := exec.Command("ps", "-p", strconv.Itoa(pid), "-v"... 阅读全文

posted @ 2018-03-17 22:16 cucy_to 阅读(198) 评论(0) 推荐(0) 编辑

1.5 获取文件路径

摘要: ```go package main import ( "fmt" "os" "path/filepath" ) func main() { ex, err := os.Executable() if err != nil { panic(err) } // Path to executable file fmt.Println("绝对路径: ", ex) // 绝对路径... 阅读全文

posted @ 2018-03-17 22:11 cucy_to 阅读(131) 评论(0) 推荐(0) 编辑

1.4 用os环境变量里获取值

摘要: 1 2 不存在则报错 3 设置获取删除环境变量 阅读全文

posted @ 2018-03-17 22:05 cucy_to 阅读(436) 评论(0) 推荐(0) 编辑

1.3命令行参数获取 flag

摘要: ```go package main import ( "flag" "fmt" "log" "os" "strings" ) // Custom type need to implement // flag.Value interface to be able to // use it in fl 阅读全文

posted @ 2018-03-17 21:55 cucy_to 阅读(873) 评论(0) 推荐(0) 编辑

1.2获取命令行参数

摘要: ```go package main import ( "fmt" "os" ) func main() { args := os.Args // all command line args println(args) // The first argument, zero item from array, // is the name of the called binar... 阅读全文

posted @ 2018-03-17 21:41 cucy_to 阅读(131) 评论(0) 推荐(0) 编辑

1.1获取go运行版本信息

摘要: ```go package main import ( "log" "runtime" ) const info = ` Application %s starting. The binary was build by GO: %s` func main() { log.Printf(info, " 阅读全文

posted @ 2018-03-17 21:25 cucy_to 阅读(1248) 评论(0) 推荐(0) 编辑

11.exporting 导出

摘要: Declare and access exported identifiers Pkg Declare and access exported identifiers Main Declare unexported identifiers and restrictions Pkg ( Declare 阅读全文

posted @ 2018-03-17 19:10 cucy_to 阅读(168) 评论(0) 推荐(0) 编辑

10.functions

摘要: Return multiple values go // Sample program to show how functions can return multiple values while using // named and struct types. package main impor 阅读全文

posted @ 2018-03-17 18:57 cucy_to 阅读(140) 评论(0) 推荐(0) 编辑

9.interface

摘要: method set go package main import "fmt" // Sample program to show how polymorphic behavior with interfaces. // 示例程序演示多态行为与接口的关系。 // reader is an inter 阅读全文

posted @ 2018-03-17 17:38 cucy_to 阅读(153) 评论(0) 推荐(0) 编辑

8. Embedding 嵌入

摘要: Declaring Fields Embedding types Embedded types and interfaces Outer and inner type interface implementations 外部和内部类型接口实现。 练习 阅读全文

posted @ 2018-03-17 01:19 cucy_to 阅读(141) 评论(0) 推荐(0) 编辑

7.pointers

摘要: Sharing data I Sharing data II Escape Analysis 溢出分析 练习 阅读全文

posted @ 2018-03-17 00:51 cucy_to 阅读(157) 评论(0) 推荐(0) 编辑

导航