Skip to content

Commit

Permalink
Merge pull request #1 from Antonboom/productionization
Browse files Browse the repository at this point in the history
Productionization
  • Loading branch information
catenacyber authored Oct 18, 2023
2 parents 9c47f05 + c81d120 commit 3bdffdf
Show file tree
Hide file tree
Showing 14 changed files with 1,324 additions and 323 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
main:
runs-on: ubuntu-latest
env:
GO_VERSION: '1.20'
GOLANGCI_LINT_VERSION: 1.54.2
CGO_ENABLED: 0
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ^${{ env.GO_VERSION }}

- name: Checkout code
uses: actions/checkout@v3

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Check and get dependencies
run: |
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}

- name: Make
run: make
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: fmt tidy lint test bench install

default: fmt tidy lint test install

fmt:
go fmt ./...

tidy:
go mod tidy

lint:
golangci-lint run

test:
go test ./...

bench:
go test -bench=Bench ./...

install:
go install .
gostrconv -h 2>&1 | head -n1
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# gostrconv
Gostrconv: Golang linter for performance, aiming at usages of `fmt.Sprintf` which have faster alternatives.

# Usage
[![CI](https://github.com/catenacyber/gostrconv/actions/workflows/ci.yml/badge.svg)](https://github.com/catenacyber/gostrconv/actions/workflows/ci.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/catenacyber/gostrconv)](https://goreportcard.com/report/github.com/catenacyber/gostrconv?dummy=unused)

./gostrconv file.go
Golang linter for performance, aiming at usages of `fmt.Sprintf` which have faster alternatives.

Rewrites `fmt.Sprintf("%d",` into faster `strconv.Itoa` and such
## Installation

```sh
go get github.com/catenacyber/gostrconv@latest
```

## Usage

```sh
gostrconv --fix ./...
```

### Replacements

```
fmt.Sprintf("%s", strVal) -> strVal
fmt.Sprintf("%t", boolVal) -> strconv.FormatBool(boolBal)
fmt.Sprintf("%x", hash) -> hex.EncodeToString(hash)
fmt.Sprintf("%d", id) -> strconv.Itoa(id)
fmt.Sprintf("%v", version) -> strconv.FormatUint(uint64(version), 10)
```

More in [tests](./analyzer/testdata/src/p/p.go).
Loading

0 comments on commit 3bdffdf

Please sign in to comment.