diff --git a/sort-cli/config.go b/cmd/sort-cli/config.go similarity index 91% rename from sort-cli/config.go rename to cmd/sort-cli/config.go index 0cd8c29..5edf70d 100644 --- a/sort-cli/config.go +++ b/cmd/sort-cli/config.go @@ -2,8 +2,6 @@ package main import "flag" -const stdin = "-" - type Config struct { Key int Numeric bool @@ -23,6 +21,6 @@ func (c *Config) ParseFlags() { c.Sources = flag.Args() if len(c.Sources) == 0 { - c.Sources = []string{stdin} + c.Sources = []string{"-"} } } diff --git a/sort-cli/main.go b/cmd/sort-cli/main.go similarity index 72% rename from sort-cli/main.go rename to cmd/sort-cli/main.go index 62b9d53..614321a 100644 --- a/sort-cli/main.go +++ b/cmd/sort-cli/main.go @@ -2,6 +2,8 @@ package main import ( "os" + + sortcli "git.grachevko.ru/grachevko/h/sort-cli" ) func main() { @@ -18,8 +20,8 @@ func run() string { cfg := &Config{} cfg.ParseFlags() - lines := content{} - lines.Load(open(cfg.Sources)) + lines := sortcli.Content{} + lines.Load(sortcli.Open(cfg.Sources)) if cfg.Unique { lines.Uniques() diff --git a/sort-cli/main_test.go b/cmd/sort-cli/main_test.go similarity index 100% rename from sort-cli/main_test.go rename to cmd/sort-cli/main_test.go diff --git a/sort-cli/testdata/first b/cmd/sort-cli/testdata/first similarity index 100% rename from sort-cli/testdata/first rename to cmd/sort-cli/testdata/first diff --git a/sort-cli/go.mod b/go.mod similarity index 54% rename from sort-cli/go.mod rename to go.mod index 3377927..d070bb3 100644 --- a/sort-cli/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ -module sort-cli +module git.grachevko.ru/grachevko/h -go 1.21.6 +go 1.22.2 require ( - github.com/stretchr/testify v1.8.4 - golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 + github.com/stretchr/testify v1.9.0 + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 ) require ( diff --git a/merge-channel/go.sum b/go.sum similarity index 65% rename from merge-channel/go.sum rename to go.sum index fa4b6e6..bb8106c 100644 --- a/merge-channel/go.sum +++ b/go.sum @@ -2,8 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/lru/Makefile b/lru/Makefile deleted file mode 100644 index 4543fa9..0000000 --- a/lru/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -.DEFAULT_GOAL := help - -# ==================================================================================== # -# HELPERS -# ==================================================================================== # - -## help: print this help message -.PHONY: help -help: - @echo 'Usage:' - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' - - -# ==================================================================================== # -# QUALITY CONTROL -# ==================================================================================== # - -## tidy: format code and tidy modfile -.PHONY: tidy -tidy: - go fmt ./... - go mod tidy -v - -## audit: run quality control checks -.PHONY: audit -audit: - go mod verify - go vet ./... - go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./... - go run golang.org/x/vuln/cmd/govulncheck@latest ./... - go test -race -buildvcs -vet=off ./... - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v ./... - - -# ==================================================================================== # -# DEVELOPMENT -# ==================================================================================== # - -## test: run all tests -.PHONY: test -test: - go test -v -race -buildvcs ./... - -## test/cover: run all tests and display coverage -.PHONY: test/cover -test/cover: - go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./... - go tool cover -html=/tmp/coverage.out diff --git a/lru/go.mod b/lru/go.mod deleted file mode 100644 index 1c7dc42..0000000 --- a/lru/go.mod +++ /dev/null @@ -1,11 +0,0 @@ -module lru - -go 1.21.6 - -require github.com/stretchr/testify v1.8.4 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/lru/go.sum b/lru/go.sum deleted file mode 100644 index fa4b6e6..0000000 --- a/lru/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/merge-channel/Makefile b/merge-channel/Makefile deleted file mode 100644 index 977c1c9..0000000 --- a/merge-channel/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -.DEFAULT_GOAL := help - -# ==================================================================================== # -# HELPERS -# ==================================================================================== # - -## help: print this help message -.PHONY: help -help: - @echo 'Usage:' - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' - -## all: tidy + audit + test/cover -all: generate tidy test lint test/cover - - -# ==================================================================================== # -# QUALITY CONTROL -# ==================================================================================== # - -## tidy: format code and tidy modfile -.PHONY: tidy -tidy: - go fmt ./... - goimports -local=$(shell cat go.mod | grep module | awk '{print $$2}')/ -w . - go mod tidy -v - -## audit: run quality control checks -.PHONY: lint -lint: - go mod verify - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v ./... - - -# ==================================================================================== # -# DEVELOPMENT -# ==================================================================================== # - -## generate: run all generators -.PHONY: generate -generate: - go generate ./... - -## test: run all tests -.PHONY: test -test: - go test -race -buildvcs ./... - -## test/cover: run all tests and display coverage -.PHONY: test/cover -test/cover: - go test -race -buildvcs -coverprofile=/tmp/coverage.out ./... - go tool cover -html=/tmp/coverage.out diff --git a/merge-channel/go.mod b/merge-channel/go.mod deleted file mode 100644 index 3147e31..0000000 --- a/merge-channel/go.mod +++ /dev/null @@ -1,11 +0,0 @@ -module merge-channel - -go 1.21.6 - -require github.com/stretchr/testify v1.8.4 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/merge-channel/main.go b/merge-channel/main.go index 6a581c5..5cd20b4 100644 --- a/merge-channel/main.go +++ b/merge-channel/main.go @@ -1,11 +1,11 @@ -package main +package mergechannel import ( "errors" "sync" ) -var InsufficientChannelsErr = errors.New("channels count must be >2") +var ErrInsufficientChannels = errors.New("channels count must be >2") func merge[T any](channels ...<-chan T) (<-chan T, error) { out := make(chan T) @@ -13,7 +13,7 @@ func merge[T any](channels ...<-chan T) (<-chan T, error) { if len(channels) < 2 { close(out) - return out, InsufficientChannelsErr + return out, ErrInsufficientChannels } var wg sync.WaitGroup diff --git a/merge-channel/main_test.go b/merge-channel/main_test.go index 622c4c4..6ca591a 100644 --- a/merge-channel/main_test.go +++ b/merge-channel/main_test.go @@ -1,4 +1,4 @@ -package main +package mergechannel import ( "testing" @@ -32,5 +32,5 @@ func TestInsufficient(t *testing.T) { a := make(chan int) _, err := merge(a) - assert.Equal(t, err, InsufficientChannelsErr) + assert.Equal(t, err, ErrInsufficientChannels) } diff --git a/pipeline/Makefile b/pipeline/Makefile deleted file mode 100644 index 977c1c9..0000000 --- a/pipeline/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -.DEFAULT_GOAL := help - -# ==================================================================================== # -# HELPERS -# ==================================================================================== # - -## help: print this help message -.PHONY: help -help: - @echo 'Usage:' - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' - -## all: tidy + audit + test/cover -all: generate tidy test lint test/cover - - -# ==================================================================================== # -# QUALITY CONTROL -# ==================================================================================== # - -## tidy: format code and tidy modfile -.PHONY: tidy -tidy: - go fmt ./... - goimports -local=$(shell cat go.mod | grep module | awk '{print $$2}')/ -w . - go mod tidy -v - -## audit: run quality control checks -.PHONY: lint -lint: - go mod verify - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v ./... - - -# ==================================================================================== # -# DEVELOPMENT -# ==================================================================================== # - -## generate: run all generators -.PHONY: generate -generate: - go generate ./... - -## test: run all tests -.PHONY: test -test: - go test -race -buildvcs ./... - -## test/cover: run all tests and display coverage -.PHONY: test/cover -test/cover: - go test -race -buildvcs -coverprofile=/tmp/coverage.out ./... - go tool cover -html=/tmp/coverage.out diff --git a/pipeline/go.mod b/pipeline/go.mod deleted file mode 100644 index 0c38406..0000000 --- a/pipeline/go.mod +++ /dev/null @@ -1,11 +0,0 @@ -module pipeline - -go 1.21.6 - -require github.com/stretchr/testify v1.8.4 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/pipeline/go.sum b/pipeline/go.sum deleted file mode 100644 index fa4b6e6..0000000 --- a/pipeline/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pipeline/main.go b/pipeline/pipeline.go similarity index 91% rename from pipeline/main.go rename to pipeline/pipeline.go index adce226..0dc07e3 100644 --- a/pipeline/main.go +++ b/pipeline/pipeline.go @@ -1,4 +1,4 @@ -package main +package pipeline func Pipe[In any, Out any](in <-chan In, pipe func(In) Out) <-chan Out { out := make(chan Out) diff --git a/pipeline/main_test.go b/pipeline/pipeline_test.go similarity index 93% rename from pipeline/main_test.go rename to pipeline/pipeline_test.go index 54aeabd..6a2f69b 100644 --- a/pipeline/main_test.go +++ b/pipeline/pipeline_test.go @@ -1,4 +1,4 @@ -package main +package pipeline import ( "testing" diff --git a/semaphore/Makefile b/semaphore/Makefile deleted file mode 100644 index 977c1c9..0000000 --- a/semaphore/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -.DEFAULT_GOAL := help - -# ==================================================================================== # -# HELPERS -# ==================================================================================== # - -## help: print this help message -.PHONY: help -help: - @echo 'Usage:' - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' - -## all: tidy + audit + test/cover -all: generate tidy test lint test/cover - - -# ==================================================================================== # -# QUALITY CONTROL -# ==================================================================================== # - -## tidy: format code and tidy modfile -.PHONY: tidy -tidy: - go fmt ./... - goimports -local=$(shell cat go.mod | grep module | awk '{print $$2}')/ -w . - go mod tidy -v - -## audit: run quality control checks -.PHONY: lint -lint: - go mod verify - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v ./... - - -# ==================================================================================== # -# DEVELOPMENT -# ==================================================================================== # - -## generate: run all generators -.PHONY: generate -generate: - go generate ./... - -## test: run all tests -.PHONY: test -test: - go test -race -buildvcs ./... - -## test/cover: run all tests and display coverage -.PHONY: test/cover -test/cover: - go test -race -buildvcs -coverprofile=/tmp/coverage.out ./... - go tool cover -html=/tmp/coverage.out diff --git a/semaphore/go.mod b/semaphore/go.mod deleted file mode 100644 index 5d89c1e..0000000 --- a/semaphore/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module semaphore - -go 1.21.6 diff --git a/semaphore/main.go b/semaphore/semaphore.go similarity index 98% rename from semaphore/main.go rename to semaphore/semaphore.go index e3ba151..6225e29 100644 --- a/semaphore/main.go +++ b/semaphore/semaphore.go @@ -1,4 +1,4 @@ -package main +package semaphore import ( "context" diff --git a/semaphore/main_test.go b/semaphore/semaphore_test.go similarity index 75% rename from semaphore/main_test.go rename to semaphore/semaphore_test.go index f53da0c..4a1c4ea 100644 --- a/semaphore/main_test.go +++ b/semaphore/semaphore_test.go @@ -1,4 +1,4 @@ -package main +package semaphore import ( "testing" diff --git a/sort-cli/Makefile b/sort-cli/Makefile deleted file mode 100644 index 19ff9ab..0000000 --- a/sort-cli/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -.DEFAULT_GOAL := help - -# ==================================================================================== # -# HELPERS -# ==================================================================================== # - -## help: print this help message -.PHONY: help -help: - @echo 'Usage:' - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' - -## all: tidy + audit + test/cover -all: tidy audit test/cover - -# ==================================================================================== # -# QUALITY CONTROL -# ==================================================================================== # - -## tidy: format code and tidy modfile -.PHONY: tidy -tidy: - go fmt ./... - go mod tidy -v - -## audit: run quality control checks -.PHONY: audit -audit: - go mod verify - go vet ./... - go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./... - go run golang.org/x/vuln/cmd/govulncheck@latest ./... - go test -race -buildvcs -vet=off ./... - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v ./... - - -# ==================================================================================== # -# DEVELOPMENT -# ==================================================================================== # - -## test: run all tests -.PHONY: test -test: - go test -v -race -buildvcs ./... - -## test/cover: run all tests and display coverage -.PHONY: test/cover -test/cover: - go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./... - go tool cover -html=/tmp/coverage.out diff --git a/sort-cli/content.go b/sort-cli/content.go index aa36569..f552317 100644 --- a/sort-cli/content.go +++ b/sort-cli/content.go @@ -1,4 +1,4 @@ -package main +package sortcli import ( "bufio" @@ -13,9 +13,9 @@ import ( // NL New line constant const NL = "\n" -type content [][]byte +type Content [][]byte -func (c *content) Sort(reverse bool) { +func (c *Content) Sort(reverse bool) { slices.SortFunc(*c, func(a, b []byte) int { if reverse { a, b = b, a @@ -25,10 +25,10 @@ func (c *content) Sort(reverse bool) { }) } -func (c *content) Uniques() { +func (c *Content) Uniques() { m := make(map[string]struct{}, len(*c)) - *c = slices.DeleteFunc[content, []byte](*c, func(line []byte) bool { + *c = slices.DeleteFunc[Content, []byte](*c, func(line []byte) bool { if _, ok := m[string(line)]; !ok { m[string(line)] = struct{}{} @@ -39,7 +39,7 @@ func (c *content) Uniques() { }) } -func (c *content) String() string { +func (c *Content) String() string { lines := *c var n int @@ -64,7 +64,7 @@ func (c *content) String() string { return sb.String() } -func (c *content) Load(r io.Reader) { +func (c *Content) Load(r io.Reader) { br := bufio.NewReader(r) for { diff --git a/sort-cli/content_test.go b/sort-cli/content_test.go index 5929c13..6d8e548 100644 --- a/sort-cli/content_test.go +++ b/sort-cli/content_test.go @@ -1,4 +1,4 @@ -package main +package sortcli import ( "strings" @@ -16,7 +16,7 @@ Africa ` func TestLoad(t *testing.T) { - c := &content{} + c := &Content{} c.Load(strings.NewReader(input)) assert.Equal(t, input, c.String()) @@ -42,7 +42,7 @@ America`, tc := tc t.Run(tc.Name, func(t *testing.T) { - c := &content{} + c := &Content{} c.Load(strings.NewReader(tc.Content)) c.Uniques() diff --git a/sort-cli/go.sum b/sort-cli/go.sum deleted file mode 100644 index 2939b8f..0000000 --- a/sort-cli/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o= -golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sort-cli/loader.go b/sort-cli/loader.go index d9d336d..4c0654d 100644 --- a/sort-cli/loader.go +++ b/sort-cli/loader.go @@ -1,4 +1,4 @@ -package main +package sortcli import ( "io" @@ -6,13 +6,13 @@ import ( "os" ) -func open(sources []string) io.Reader { +func Open(sources []string) io.Reader { rs := make([]io.Reader, 0, len(sources)) for _, source := range sources { var r io.Reader - if source == stdin { + if source == "-" { r = os.Stdin } else { if _, err := os.Stat(source); err != nil { diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/unique-chars/Makefile b/unique-chars/Makefile deleted file mode 100644 index 4543fa9..0000000 --- a/unique-chars/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -.DEFAULT_GOAL := help - -# ==================================================================================== # -# HELPERS -# ==================================================================================== # - -## help: print this help message -.PHONY: help -help: - @echo 'Usage:' - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' - - -# ==================================================================================== # -# QUALITY CONTROL -# ==================================================================================== # - -## tidy: format code and tidy modfile -.PHONY: tidy -tidy: - go fmt ./... - go mod tidy -v - -## audit: run quality control checks -.PHONY: audit -audit: - go mod verify - go vet ./... - go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./... - go run golang.org/x/vuln/cmd/govulncheck@latest ./... - go test -race -buildvcs -vet=off ./... - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v ./... - - -# ==================================================================================== # -# DEVELOPMENT -# ==================================================================================== # - -## test: run all tests -.PHONY: test -test: - go test -v -race -buildvcs ./... - -## test/cover: run all tests and display coverage -.PHONY: test/cover -test/cover: - go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./... - go tool cover -html=/tmp/coverage.out diff --git a/unique-chars/go.mod b/unique-chars/go.mod deleted file mode 100644 index e0e56d6..0000000 --- a/unique-chars/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module uniqueschars - -go 1.21.6 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/unique-chars/go.sum b/unique-chars/go.sum deleted file mode 100644 index 8cf6655..0000000 --- a/unique-chars/go.sum +++ /dev/null @@ -1,9 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/unique-chars/main.go b/unique-chars/uniquechars.go similarity index 100% rename from unique-chars/main.go rename to unique-chars/uniquechars.go diff --git a/unique-chars/main_test.go b/unique-chars/uniquechars_test.go similarity index 100% rename from unique-chars/main_test.go rename to unique-chars/uniquechars_test.go diff --git a/worker-pool/Makefile b/worker-pool/Makefile deleted file mode 100644 index 977c1c9..0000000 --- a/worker-pool/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -.DEFAULT_GOAL := help - -# ==================================================================================== # -# HELPERS -# ==================================================================================== # - -## help: print this help message -.PHONY: help -help: - @echo 'Usage:' - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' - -## all: tidy + audit + test/cover -all: generate tidy test lint test/cover - - -# ==================================================================================== # -# QUALITY CONTROL -# ==================================================================================== # - -## tidy: format code and tidy modfile -.PHONY: tidy -tidy: - go fmt ./... - goimports -local=$(shell cat go.mod | grep module | awk '{print $$2}')/ -w . - go mod tidy -v - -## audit: run quality control checks -.PHONY: lint -lint: - go mod verify - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v ./... - - -# ==================================================================================== # -# DEVELOPMENT -# ==================================================================================== # - -## generate: run all generators -.PHONY: generate -generate: - go generate ./... - -## test: run all tests -.PHONY: test -test: - go test -race -buildvcs ./... - -## test/cover: run all tests and display coverage -.PHONY: test/cover -test/cover: - go test -race -buildvcs -coverprofile=/tmp/coverage.out ./... - go tool cover -html=/tmp/coverage.out diff --git a/worker-pool/go.mod b/worker-pool/go.mod deleted file mode 100644 index a01eea9..0000000 --- a/worker-pool/go.mod +++ /dev/null @@ -1,11 +0,0 @@ -module worker-pool - -go 1.21.6 - -require github.com/stretchr/testify v1.8.4 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/worker-pool/main.go b/worker-pool/workerpool.go similarity index 93% rename from worker-pool/main.go rename to worker-pool/workerpool.go index 1abe752..b57f366 100644 --- a/worker-pool/main.go +++ b/worker-pool/workerpool.go @@ -1,4 +1,4 @@ -package main +package workerpool import ( "fmt" diff --git a/worker-pool/main_test.go b/worker-pool/workerpool_test.go similarity index 96% rename from worker-pool/main_test.go rename to worker-pool/workerpool_test.go index 1511387..8639a9a 100644 --- a/worker-pool/main_test.go +++ b/worker-pool/workerpool_test.go @@ -1,4 +1,4 @@ -package main +package workerpool import ( "fmt"