分类 golang 下的文章

package main

import (
    "fmt"

    "github.com/tealeg/xlsx"
)

func main() {
    xlFile, err := xlsx.OpenFile("Item.xlsx")
    if err != nil {
        panic(err.Error())
    }

    for _, v := range xlFile.Sheets[0].Rows {
        if len(v.Cells) > 0 {
            fmt.Printf("%s %s\n", v.Cells[1].String(), v.Cells[0].String())
        }
    }
}

package main

import "fmt"

var VERSION string
var PLATFORM string

func main() {
    fmt.Println("当前版本:"+VERSION)
}

go build -ldflags="-X main.VERSION=v1.0.1 -X main. PLATFORM=android"

xxx, err := json.Marshal(data)
if err != nil {
    return nil, err
}

resp, err := http.Post(url, "application/json", bytes.NewReader(xxx))
if err != nil {
    return nil, err
}
defer resp.Body.Close()

var data2 map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
    return nil, err
}

return data2, nil

结构化日志方便查询

package main

import (
    "errors"

    "go.uber.org/zap"
)

func main() {
    // logger, err := zap.NewProduction()
    logger, err := zap.NewDevelopment()
    if err != nil {
        panic(err.Error())
    }
    logger.Info("hello world", zap.String("user", "咪了个猫"), zap.Int("age", 666))

    err = errors.New("我是一个错误")
    logger.Error("报错啦", zap.Error(err), zap.String("xxx", "我是一个参数"))

    logger.Info("hello world", zap.String("user", "咪了个猫"), zap.Error(err))
}


2020-09-22T16:51:33.156+0800    INFO    xxx3/main.go:15 hello world     {"user": "咪了个猫", "age": 666}
2020-09-22T16:51:33.156+0800    ERROR   xxx3/main.go:18 报错啦  {"error": "我是一个错误", "xxx": "我是一个参数"}
main.main
        /Users/wameidemao/Desktop/xxx3/main.go:18
runtime.main
        /usr/local/go/src/runtime/proc.go:204
2020-09-22T16:51:33.156+0800    INFO    xxx3/main.go:20 hello world     {"user": "咪了个猫", "error": "我是一个错误"}