Skip to content

Commit

Permalink
Merge pull request #4 from reugn/v0.2.0
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
reugn authored Aug 31, 2024
2 parents f5018bf + 758fdda commit 71fb97d
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 175 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
name: Test

on: [push, pull_request]
on:
push:
branches:
- '**'
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.14.x, 1.15.x]
go-version: [1.20.x]
steps:
- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Test
run: go test ./...
run: go test -race ./...
24 changes: 8 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
run:
timeout: 2m

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exhaustive
- errname
- errorlint
- funlen
- gci
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- scopelint
- prealloc
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# tpack
[![Test Status](https://github.com/reugn/tpack/workflows/Test/badge.svg)](https://github.com/reugn/tpack/actions?query=workflow%3ATest)
[![Test](https://github.com/reugn/tpack/actions/workflows/test.yml/badge.svg)](https://github.com/reugn/tpack/actions/workflows/test.yml)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/reugn/tpack)](https://pkg.go.dev/github.com/reugn/tpack)
[![Go Report Card](https://goreportcard.com/badge/github.com/reugn/tpack)](https://goreportcard.com/report/github.com/reugn/tpack)

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

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

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

## Examples
See ETL workflow in the examples folder.
## Usage
See the ETL workflow in the [examples](examples) folder.

```go
package main

import "github.com/reugn/tpack"

func main() {
tpack.NewPackerStd(tpack.NewFunctionProcessor(
tpack.NewPackerStd(tpack.NewProcessor(
doETL,
)).Execute()
}
```

Test command
```sh
cat input.txt | go run *.go 2>/dev/null | wc -l
```

## License
Licensed under the MIT License.
Licensed under the MIT License.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Package tpack provides tools to pack a Go workflow as a Unix-style pipeline command.
// Package tpack provides tools to package Go workflows as Unix-style pipeline commands.
package tpack
45 changes: 25 additions & 20 deletions examples/etl/etl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,46 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"time"
)

var db map[string]string
type store map[string]string

func (s store) get(key string) (string, error) {
time.Sleep(200 * time.Millisecond) // simulate latency
value, exists := s[key]
if !exists {
return "", fmt.Errorf("%s not found", key)
}
return value, nil
}

// emulates a database store
var db store

// initialize the global db from the file
func init() {
f, err := ioutil.ReadFile("db.json")
data, err := os.ReadFile("db.json")
if err != nil {
log.Fatal(err)
}
if err := json.Unmarshal(f, &db); err != nil {
if err := json.Unmarshal(data, &db); err != nil {
log.Fatal(err)
}
}

func doETL(in []byte) ([][]byte, error) {
var res [][]byte
s := string(in)
if strings.HasPrefix(s, "+") {
key := strings.Replace(s, "+", "", 1)
value, err := getByKey(key)
func doETL(in string) ([]string, error) {
var result []string
key, found := strings.CutPrefix(in, "+")
if found {
value, err := db.get(key)
if err != nil {
return nil, err
}
return append(res, []byte(value)), nil
return append(result, value), nil
}
return nil, nil
}

func getByKey(key string) (string, error) {
value, exists := db[key]
if !exists {
return "", fmt.Errorf("%s not found", key)
}
return value, nil
return result, nil
}
2 changes: 1 addition & 1 deletion examples/etl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import "github.com/reugn/tpack"

func main() {
tpack.NewPackerStd(tpack.NewFunctionProcessor(
tpack.NewPackerStd(tpack.NewProcessor(
doETL,
)).Execute()
}
51 changes: 0 additions & 51 deletions function_processor.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/reugn/tpack

go 1.15
go 1.20
Loading

0 comments on commit 71fb97d

Please sign in to comment.