
Go
tpieo
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
go file operation
f, err := os.Open(filename) //read only f, err := os.OpenFile(filename, os.O_WRONLY|os.O_APPEND|os.O_CREAE, 777) //append os.O_RDONLY : read only os.O_WRONLY: write only os.O_RDWR: read and write os.O_APPEND: write with append os.O_CREAT: create ne原创 2022-05-15 18:12:45 · 266 阅读 · 0 评论 -
go connect mysql
connect package main import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysql" ) var db *sql.DB func init() { var err error //format: username:password@protocal(host:port)/database db, err = sql.Open("mysql", "root:123456@tcp(127.0.0.1:330原创 2022-05-13 16:59:49 · 436 阅读 · 0 评论 -
go typical variable scope bug
problem var cwd string func init() { cwd, err := os.Getwd() // compile error: unused: cwd if err != nil { log.Fatalf("os.Getwd failed: %v", err) } } := will make a local cwd variable, and the package variable cwd is still empty value.原创 2022-05-09 15:05:19 · 356 阅读 · 0 评论 -
go modules
init a project (module) named “gotest” go mod init gotest //go: creating new go.mod: module gotest create two packages to see how to import a package in the local space (1) hello package (2) main package (3) path run the project (module) go run go.原创 2022-05-09 13:51:37 · 106 阅读 · 0 评论 -
go strings
package main import ( "fmt" "strings" ) func main() { a := "hello" fmt.Println(strings.Contains(a, "ll")) // true fmt.Println(strings.Count(a, "l")) // 2 fmt.Println(strings.HasPrefix(a, "he")) // tru原创 2022-05-08 17:43:42 · 293 阅读 · 0 评论 -
go convert string to json quick solution
package main import ( "encoding/json" "fmt" ) func main() { s := `{"a": true, "b": 1, "c": "666"}` m := make(map[string]interface{}) json.Unmarshal([]byte(s), &m) fmt.Println(m["a"]) //true fmt.Println(m["b"]) //1 fmt.Println(m) //map原创 2022-05-07 21:17:46 · 376 阅读 · 0 评论