Skip to content

Commit 71fb97d

Browse files
authored
Merge pull request #4 from reugn/v0.2.0
v0.2.0
2 parents f5018bf + 758fdda commit 71fb97d

File tree

11 files changed

+307
-175
lines changed

11 files changed

+307
-175
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
name: Test
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- master
410

511
jobs:
612
test:
713
runs-on: ubuntu-latest
814
strategy:
915
matrix:
10-
go-version: [1.14.x, 1.15.x]
16+
go-version: [1.20.x]
1117
steps:
1218
- name: Setup Go
13-
uses: actions/setup-go@v2
19+
uses: actions/setup-go@v5
1420
with:
1521
go-version: ${{ matrix.go-version }}
22+
1623
- name: Checkout code
17-
uses: actions/checkout@v2
24+
uses: actions/checkout@v4
25+
1826
- name: Test
19-
run: go test ./...
27+
run: go test -race ./...

.golangci.yml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,31 @@
1+
run:
2+
timeout: 2m
3+
14
linters:
25
disable-all: true
36
enable:
4-
- bodyclose
5-
- deadcode
6-
- depguard
7-
- dogsled
87
- dupl
98
- errcheck
10-
- exhaustive
9+
- errname
10+
- errorlint
1111
- funlen
12+
- gci
1213
- goconst
1314
- gocritic
1415
- gocyclo
1516
- gofmt
1617
- goimports
17-
- golint
18-
- goprintffuncname
1918
- gosec
2019
- gosimple
2120
- govet
2221
- ineffassign
23-
- interfacer
2422
- lll
2523
- misspell
26-
- nakedret
27-
- noctx
28-
- nolintlint
29-
- rowserrcheck
30-
- scopelint
24+
- prealloc
25+
- revive
3126
- staticcheck
32-
- structcheck
3327
- stylecheck
3428
- typecheck
3529
- unconvert
3630
- unparam
3731
- unused
38-
- varcheck
39-
- whitespace

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# tpack
2-
[![Test Status](https://github.com/reugn/tpack/workflows/Test/badge.svg)](https://github.com/reugn/tpack/actions?query=workflow%3ATest)
2+
[![Test](https://github.com/reugn/tpack/actions/workflows/test.yml/badge.svg)](https://github.com/reugn/tpack/actions/workflows/test.yml)
33
[![PkgGoDev](https://pkg.go.dev/badge/github.com/reugn/tpack)](https://pkg.go.dev/github.com/reugn/tpack)
44
[![Go Report Card](https://goreportcard.com/badge/github.com/reugn/tpack)](https://goreportcard.com/report/github.com/reugn/tpack)
55

6-
Pack a Go workflow/function as a Unix-style pipeline command.
6+
Pack a Go workflow/function into a Unix-style pipeline command.
77

88
![tpack](./docs/images/tpack.png)
99

@@ -13,23 +13,25 @@ Pack a Go workflow/function as a Unix-style pipeline command.
1313
Use `tpack` to write Go applications that act as pipeline commands.
1414
Employ channels, goroutines, regular expressions and more to build powerful concurrent workflows.
1515

16-
## Examples
17-
See ETL workflow in the examples folder.
16+
## Usage
17+
See the ETL workflow in the [examples](examples) folder.
18+
1819
```go
1920
package main
2021

2122
import "github.com/reugn/tpack"
2223

2324
func main() {
24-
tpack.NewPackerStd(tpack.NewFunctionProcessor(
25+
tpack.NewPackerStd(tpack.NewProcessor(
2526
doETL,
2627
)).Execute()
2728
}
2829
```
30+
2931
Test command
3032
```sh
3133
cat input.txt | go run *.go 2>/dev/null | wc -l
3234
```
3335

3436
## License
35-
Licensed under the MIT License.
37+
Licensed under the MIT License.

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// Package tpack provides tools to pack a Go workflow as a Unix-style pipeline command.
1+
// Package tpack provides tools to package Go workflows as Unix-style pipeline commands.
22
package tpack

examples/etl/etl.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,46 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
76
"log"
7+
"os"
88
"strings"
9+
"time"
910
)
1011

11-
var db map[string]string
12+
type store map[string]string
1213

14+
func (s store) get(key string) (string, error) {
15+
time.Sleep(200 * time.Millisecond) // simulate latency
16+
value, exists := s[key]
17+
if !exists {
18+
return "", fmt.Errorf("%s not found", key)
19+
}
20+
return value, nil
21+
}
22+
23+
// emulates a database store
24+
var db store
25+
26+
// initialize the global db from the file
1327
func init() {
14-
f, err := ioutil.ReadFile("db.json")
28+
data, err := os.ReadFile("db.json")
1529
if err != nil {
1630
log.Fatal(err)
1731
}
18-
if err := json.Unmarshal(f, &db); err != nil {
32+
if err := json.Unmarshal(data, &db); err != nil {
1933
log.Fatal(err)
2034
}
2135
}
2236

23-
func doETL(in []byte) ([][]byte, error) {
24-
var res [][]byte
25-
s := string(in)
26-
if strings.HasPrefix(s, "+") {
27-
key := strings.Replace(s, "+", "", 1)
28-
value, err := getByKey(key)
37+
func doETL(in string) ([]string, error) {
38+
var result []string
39+
key, found := strings.CutPrefix(in, "+")
40+
if found {
41+
value, err := db.get(key)
2942
if err != nil {
3043
return nil, err
3144
}
32-
return append(res, []byte(value)), nil
45+
return append(result, value), nil
3346
}
34-
return nil, nil
35-
}
36-
37-
func getByKey(key string) (string, error) {
38-
value, exists := db[key]
39-
if !exists {
40-
return "", fmt.Errorf("%s not found", key)
41-
}
42-
return value, nil
47+
return result, nil
4348
}

examples/etl/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import "github.com/reugn/tpack"
44

55
func main() {
6-
tpack.NewPackerStd(tpack.NewFunctionProcessor(
6+
tpack.NewPackerStd(tpack.NewProcessor(
77
doETL,
88
)).Execute()
99
}

function_processor.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/reugn/tpack
22

3-
go 1.15
3+
go 1.20

0 commit comments

Comments
 (0)