Skip to content

Commit

Permalink
Merge pull request #6 from Songmu/maint
Browse files Browse the repository at this point in the history
introduce Go Modules and GitHub Actions
  • Loading branch information
Songmu authored May 21, 2022
2 parents 3c87dbc + e6386e9 commit 85fcad2
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 41 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.*
!.gitignore
!.travis.yml
!.goxc.json
!.github
dist/
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

24 changes: 13 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
59 changes: 49 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,62 @@
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

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

Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
8 changes: 4 additions & 4 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ltsv_test

import (
"fmt"
"net"
"time"

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit 85fcad2

Please sign in to comment.