Skip to content

Commit

Permalink
fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
whonion committed Jun 21, 2023
1 parent 924364a commit 45d0a5e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
25 changes: 18 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
name: Lint

on: [ push, pull_request ]
on: [push, pull_request]

jobs:
lint:
lint-main:
strategy:
matrix:
platform: [ "ubuntu-latest" ]
platform: ["ubuntu-latest"]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Lint
run: make lint-go
- name: Checkout code
uses: actions/checkout@v2
- name: Lint main.go
run: make lint-go-main

lint-goroutine:
strategy:
matrix:
platform: ["ubuntu-latest"]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Lint go-routine.go
run: make lint-go-routine
31 changes: 13 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,33 @@ coverage-go-routine: ## Run coverage for go-routine.go
$(GOCMD) tool cover -func profile-go-routine.cov

## Lint:
lint: lint-go lint-dockerfile lint-yaml ## Run all available linters
Lint: lint-dockerfile lint-yaml lint-go-main lint-go-routine ## Run all available lint

lint-dockerfile: ## Lint your Dockerfile
# If dockerfile is present we lint it.
# If the Dockerfile is present, we lint it.
ifeq ($(shell test -e ./Dockerfile && echo -n yes),yes)
$(eval CONFIG_OPTION = $(shell [ -e $(shell pwd)/.hadolint.yaml ] && echo "-v $(shell pwd)/.hadolint.yaml:/root/.config/hadolint.yaml" || echo "" ))
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--format checkstyle" || echo "" ))
$(eval OUTPUT_FILE = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "| tee /dev/tty > checkstyle-report.xml" || echo "" ))
docker run --rm -i $(CONFIG_OPTION) hadolint/hadolint hadolint $(OUTPUT_OPTIONS) - < ./Dockerfile $(OUTPUT_FILE)
endif

lint-go: ## Use golintci-lint on your project
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS)
lint-go-main: ## Use golangci-lint for main.go
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle main.go | tee /dev/tty > checkstyle-report-main.xml" || echo "" ))
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS) main.go

lint-yaml: ## Use yamllint on the yaml file of your projects
lint-go-routine: ## Use golangci-lint for go-routine.go
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle go-routine.go | tee /dev/tty > checkstyle-report-goroutine.xml" || echo "" ))
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS) go-routine.go

lint-yaml: ## Use yamllint in the yaml files of your projects
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/thomaspoignant/yamllint-checkstyle
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
endif
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)

## Docker:
docker-build: ## Use the dockerfile to build the container
docker build --rm --tag $(BINARY_NAME) .

docker-release: ## Release the container with tag latest and version
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):latest
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)
# Push the docker images
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):latest
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)
docker run --rm -v $(shell pwd):/data cytopia/yamllint -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)



## Help:
help: ## Show this help.
Expand Down
6 changes: 3 additions & 3 deletions go-routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bufio"
"fmt"
"io/ioutil"
"io"
"math/rand"
"net/http"
"net/url"
Expand All @@ -26,7 +26,7 @@ func main() {
return
}

rand.Seed(time.Now().UnixNano()) // Seed random number generator
rand.New(rand.NewSource(time.Now().UnixNano())) // Create a new random generator

userAgents, err := readLines("useragents.txt")
if err != nil {
Expand Down Expand Up @@ -76,7 +76,7 @@ func main() {
}

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
Expand Down

0 comments on commit 45d0a5e

Please sign in to comment.