diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..ee8cfe7 --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,13 @@ +name: reviewdog +on: [pull_request] +jobs: + staticcheck: + name: staticcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: reviewdog/action-staticcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + fail_on_error: true diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..020f3b6 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,32 @@ +name: test +on: + push: + branches: + - "**" + pull_request: {} +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macOS-latest + - windows-latest + steps: + - name: setup go + uses: actions/setup-go@v3 + with: + go-version: 1.x + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + if: "matrix.os == 'windows-latest'" + - name: checkout + uses: actions/checkout@v3 + - name: test + run: go test -race -coverprofile coverage.out -covermode atomic ./... + - name: Send coverage + uses: codecov/codecov-action@v1 diff --git a/.gitignore b/.gitignore index 8ee0658..e7ddb6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .* !.gitignore -!.travis.yml -!.goxc.json +!.github dist/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3629ac4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go -go: -- tip -script: -- make lint -- make test -after_script: -- make cover diff --git a/Makefile b/Makefile index fff23c6..ed1cb7a 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,18 @@ -test: deps - go test +u := $(if $(update),-u) +.PHONY: deps deps: - go get -d -v -t ./... - go get golang.org/x/lint/golint - go get github.com/mattn/goveralls + go get ${u} -d + go mod tidy -lint: deps - go vet - golint -set_exit_status +.PHONY: devel-deps +devel-deps: + go install github.com/Songmu/godzil/cmd/godzil@latest -cover: deps - goveralls +.PHONY: test +test: + go test -.PHONY: test deps lint cover +.PHONY: release +release: devel-deps + godzil release diff --git a/README.md b/README.md index 178d008..488ad41 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,52 @@ go-ltsv ======= -[![Build Status](https://travis-ci.org/Songmu/go-ltsv.png?branch=master)][travis] -[![Coverage Status](https://coveralls.io/repos/Songmu/go-ltsv/badge.png?branch=master)][coveralls] -[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license] -[![GoDoc](https://godoc.org/github.com/Songmu/go-ltsv?status.svg)][godoc] - -[travis]: https://travis-ci.org/Songmu/go-ltsv -[coveralls]: https://coveralls.io/r/Songmu/go-ltsv?branch=master -[license]: https://github.com/Songmu/go-ltsv/blob/master/LICENSE -[godoc]: https://godoc.org/github.com/Songmu/go-ltsv +[![Test Status](https://github.com/Songmu/go-ltsv/workflows/test/badge.svg?branch=main)][actions] +[![Coverage Status](https://codecov.io/gh/Songmu/go-ltsv/branch/main/graph/badge.svg)][codecov] +[![MIT License](https://img.shields.io/github/license/Songmu/go-ltsv)][license] +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Songmu/go-ltsv)][PkgGoDev] + +[actions]: https://github.com/Songmu/go-ltsv/actions?workflow=test +[codecov]: https://codecov.io/gh/Songmu/go-ltsv +[license]: https://github.com/Songmu/go-ltsv/blob/main/LICENSE +[PkgGoDev]: https://pkg.go.dev/github.com/Songmu/go-ltsv + +LTSV library to map ltsv to struct. + +## Synopsis + +```go +import ( + "net" + + "github.com/Songmu/go-ltsv" +) + +type log struct { + Host net.IP + Req string + Status int + Size int + UA string + ReqTime float64 + AppTime *float64 + VHost string +} + +func main() { + ltsvLog := "time:2016-07-13T00:00:04+09:00\t" + + "host:192.0.2.1\t" + + "req:POST /api/v0/tsdb HTTP/1.1\t" + + "status:200\t" + + "size:36\t" + + "ua:ua:mackerel-agent/0.31.2 (Revision 775fad2)\t" + + "reqtime:0.087\t" + + "vhost:mackerel.io" + l := &log{} + ltsv.Unmarshal([]byte(ltsvLog), l) + ... +} +``` ## Description @@ -17,7 +54,9 @@ LTSV parser and encoder for Go with reflection ## Installation - % go get github.com/Songmu/go-ltsv +```console +% go get github.com/Songmu/go-ltsv +``` ## Author diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..69cb760 --- /dev/null +++ b/codecov.yml @@ -0,0 +1 @@ +comment: false diff --git a/encode_test.go b/encode_test.go index 4ea02de..d1cee30 100644 --- a/encode_test.go +++ b/encode_test.go @@ -48,7 +48,7 @@ var encodeTests = []struct { EmailVerified: true, Memo: "songmu.jp", }, - Output: "user:songmu\tage:36\tweight:66.6", + Output: "user:songmu\tage:36\tweight:66.6\temail_verified:true", }, { Name: "Simple without nil pointer", @@ -60,7 +60,7 @@ var encodeTests = []struct { EmailVerified: false, Memo: "songmu.jp", }, - Output: "user:songmu\tage:36\theight:169.1\tweight:66.6", + Output: "user:songmu\tage:36\theight:169.1\tweight:66.6\temail_verified:false", }, { Name: "Omit memo", @@ -69,7 +69,7 @@ var encodeTests = []struct { Age: 36, Memo: "songmu.jp", }, - Output: "user:songmu\tage:36\tweight:0", + Output: "user:songmu\tage:36\tweight:0\temail_verified:false", }, { Name: "Anthoer struct", @@ -108,7 +108,7 @@ func TestMarshal(t *testing.T) { } } else { if s != tt.Output { - t.Errorf("%s: out=%s, want=%s", tt.Name, s, tt.Output) + t.Errorf("%s:\n out =%s\n want=%s", tt.Name, s, tt.Output) } } } diff --git a/example_test.go b/example_test.go index 1d8faba..6e5fd3a 100644 --- a/example_test.go +++ b/example_test.go @@ -1,7 +1,6 @@ package ltsv_test import ( - "fmt" "net" "time" @@ -47,14 +46,10 @@ func ExampleUnmarshal() { "vhost:mackerel.io" l := log{} ltsv.Unmarshal([]byte(ltsvLog), &l) - t := l.Time - l.Time = nil - fmt.Println(t) pretty.Println(l) // Output: - // 2016-07-13 00:00:04 +0900 +0900 // ltsv_test.log{ - // Time: (*ltsv_test.logTime)(nil), + // Time: time.Date(2016, time.July, 13, 0, 0, 4, 0, time.Location("")), // Host: {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xc0, 0x0, 0x2, 0x1}, // Req: "POST /api/v0/tsdb HTTP/1.1", // Status: 200, diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2eda2b1 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/Songmu/go-ltsv + +go 1.18 + +require github.com/kr/pretty v0.3.0 + +require ( + github.com/kr/text v0.2.0 // indirect + github.com/rogpeppe/go-internal v1.6.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..801b302 --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=