From 92563ab487e810f7546f7d2e8444acbb0cc0f732 Mon Sep 17 00:00:00 2001 From: Jacopo Andrea Giola Date: Thu, 17 Oct 2024 16:16:22 +0200 Subject: [PATCH] style: add nice to have to the repository --- .devcontainer/devcontainer.json | 46 +++++++ .dockerignore | 20 +++ .editorconfig | 17 +++ .github/CODEOWNERS | 2 + .github/ISSUE_TEMPLATE/bug_report.yml | 52 ++++++++ .github/ISSUE_TEMPLATE/config.yml | 5 + .github/ISSUE_TEMPLATE/documentation.yml | 29 +++++ .github/ISSUE_TEMPLATE/new-feature.yml | 29 +++++ .github/PULL_REQUEST_TEMPLATE.md | 19 +++ .github/dependabot.yml | 51 ++++++++ .github/workflows/codeql.yaml | 45 +++++++ .github/workflows/dependency-review.yaml | 27 ++++ .gitignore | 134 ++++++++++++++++++-- .gitlab-ci.yml | 13 -- .go-version | 1 + .golangci.yaml | 98 +++++++++++++++ .goreleaser.yaml | 54 ++++++++ .markdownlint.yaml | 24 ++++ .pre-commit-config.yaml | 36 ++++++ CHANGELOG.md | 8 +- CODE_OF_CONDUCT.md | 152 +++++++++++++++-------- CONTRIBUTING.md | 88 ++++++++----- Dockerfile | 45 ++----- LICENSE | 4 +- Makefile | 86 ++++++++++--- README.md | 10 +- config/env.go | 29 +++-- go.mod | 38 +++--- go.sum | 110 +++++++--------- main.go | 29 +++-- main_test.go | 37 +++--- router.go | 29 +++-- router_test.go | 21 +++- statusroutes.go | 29 +++-- statusroutes_test.go | 27 +++- tools/GOLANGCI_LINT_VERSION | 1 + tools/GORELEASER_VERSION | 1 + tools/make/build.mk | 58 +++++++++ tools/make/clean.mk | 44 +++++++ tools/make/lint.mk | 56 +++++++++ tools/make/test.mk | 45 +++++++ 41 files changed, 1322 insertions(+), 327 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/documentation.yml create mode 100644 .github/ISSUE_TEMPLATE/new-feature.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/codeql.yaml create mode 100644 .github/workflows/dependency-review.yaml delete mode 100644 .gitlab-ci.yml create mode 100644 .go-version create mode 100644 .golangci.yaml create mode 100644 .goreleaser.yaml create mode 100644 .markdownlint.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 tools/GOLANGCI_LINT_VERSION create mode 100644 tools/GORELEASER_VERSION create mode 100644 tools/make/build.mk create mode 100644 tools/make/clean.mk create mode 100644 tools/make/lint.mk create mode 100644 tools/make/test.mk diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..84a6fbb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,46 @@ +{ + "name": "Go", + "image": "golang:1.23.2", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": {"username": "golang"}, + "ghcr.io/devcontainers/features/go:1": {"version": "none", "golangciLintVersion": "1.61.0"}, + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "moby": true, + "installDockerComposeSwitch": false + } + }, + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined" + ], + "customizations": { + "vscode": { + "settings": { + "files.eol": "\n", + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": false, + "go.coverMode": "atomic", + "go.toolsManagement.checkForUpdates": "local", + "go.lintTool": "golangci-lint", + "go.useLanguageServer": true, + "go.gopath": "/go", + "go.buildFlags": [ + "-tags=conformance,integration" + ] + }, + "extensions": [ + "redhat.vscode-yaml", + "editorconfig.editorconfig", + "davidanson.vscode-markdownlint" + ] + }, + "codespaces": { + "openFiles": [ + "README.md", + "CONTRIBUTING.md" + ] + } + } +} diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..836a3c8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,20 @@ +.devcontainer +.git +.github +.idea +.vscode +config +tools +.dockerignore +.editorconfig +.gitignore +.go-version +.golangci.yaml +.goreleaser.yaml +.markdownlint.yaml +.pre-commit-config.yaml +**.md +Dockerfile +go.* +*.go +Makefile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2b29c96 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +indent_style = tab +indent_size = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 120 + +[*.md] +trim_trailing_whitespace = false + +[*.{yaml,yml}] +indent_style = space +tab_width = 2 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..1250312 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# Actions must also be checked by security +.github/workflows @mia-platform/sig-security diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..dc79c52 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,52 @@ +name: Bug Report +description: Report a bug that you have experienced +title: "[Bug]: " +labels: +- bug +- needs triage +body: +- type: markdown + attributes: + value: "## Thank you for contributing to our project!" +- type: markdown + attributes: + value: Thanks for taking the time to fill out this bug report. +- id: version + type: input + attributes: + label: What version or versions you have tested? + description: Add one or more version where the bug is present + placeholder: ex. 1.0.0 or 1.0.0,1.0.1 +- id: operating-systems + type: checkboxes + attributes: + label: Which operating systems have you used? + description: You may select more than one. + options: + - label: macOS + - label: Windows + - label: Linux +- id: expectation + type: textarea + attributes: + label: What did you expect to happen? + description: | + Describe what did you expect to happen if this bug wasn’t there. + validations: + required: true +- id: problem + type: textarea + attributes: + label: What happened instead? + description: | + Please describe what happened and provide every detail you can for reproducing it. + validations: + required: true +- id: code-of-conduct + type: checkboxes + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](./CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project’s Code of Conduct + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..0ae8d90 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: +- name: Mia-Platform Community Support + url: https://github.com/mia-platform/community/discussions + about: Please ask and answer questions here. diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml new file mode 100644 index 0000000..f5c8ce6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -0,0 +1,29 @@ +name: Documenation +description: Request a missing documentation or the correction of a wrong one +title: "[Docs]: " +labels: +- documentation +- needs triage +body: +- type: markdown + attributes: + value: "## Thank you for contributing to our project!" +- type: markdown + attributes: + value: Thanks for taking the time to fill out this documenation request. +- id: documentation + type: textarea + attributes: + label: Documentation Revision + description: | + Please describe what you want to be documented or the docs that must be corrected and why. + validations: + required: true +- id: code-of-conduct + type: checkboxes + attributes: + label: Code of Conduct + description: By submitting this documentation revision, you agree to follow our [Code of Conduct](./CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project’s Code of Conduct + required: true diff --git a/.github/ISSUE_TEMPLATE/new-feature.yml b/.github/ISSUE_TEMPLATE/new-feature.yml new file mode 100644 index 0000000..60ef582 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/new-feature.yml @@ -0,0 +1,29 @@ +name: New Feature +description: Describe a new feature that you want implemented +title: "[Feature]: " +labels: +- enhancement +- needs triage +body: +- type: markdown + attributes: + value: "## Thank you for contributing to our project!" +- type: markdown + attributes: + value: Thanks for taking the time to fill out this feature request. +- id: new-feature + type: textarea + attributes: + label: Describe the feature + description: | + Please describe what you want to be implemented and why. + validations: + required: true +- id: code-of-conduct + type: checkboxes + attributes: + label: Code of Conduct + description: By submitting this feature, you agree to follow our [Code of Conduct](./CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project’s Code of Conduct + required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..e444eff --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,19 @@ + + +## What this PR is for? + + + +**Which issue(s) this PR fixes:** + +- Fixes # diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..a472e61 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,51 @@ +version: 2 + +updates: +# keep up to date the github actions +- package-ecosystem: github-actions + directory: / + schedule: + interval: monthly + timezone: Europe/Rome + groups: + minor-actions-dependencies: + update-types: + - minor + - patch + commit-message: + include: scope + prefix: ci + +# keep up to date the base docker image +- package-ecosystem: docker + directory: / + schedule: + interval: daily + time: "07:00" + timezone: Europe/Rome + commit-message: + include: scope + prefix: build + +# enable go dependencies security updates +- directory: / + open-pull-requests-limit: 0 + package-ecosystem: gomod + rebase-strategy: auto + schedule: + interval: daily + time: "07:00" + timezone: Europe/Rome + commit-message: + include: scope + prefix: chore + +# keep up to date devcontainers +- package-ecosystem: devcontainers + directory: "/" + schedule: + interval: monthly + timezone: Europe/Rome + commit-message: + include: scope + prefix: build diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml new file mode 100644 index 0000000..9f85411 --- /dev/null +++ b/.github/workflows/codeql.yaml @@ -0,0 +1,45 @@ +name: Code Scanning +on: + push: + branches: + - main + tags: + - "*" + pull_request: + branches: + - main + paths-ignore: + - "**/*.md" + - docs/** + - examples/** + schedule: + - cron: 0 5 * * 1 # Run every monday at 5 UTC + +env: + GORELEASER_VERSION: v2.3.2 + +jobs: + codeql: + runs-on: ubuntu-latest + permissions: + security-events: write + steps: + - name: Checkout repository + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + with: + show-progress: false + - name: Setup Golang + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 + with: + go-version-file: go.mod + - name: Setup Goreleaser + uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0 + with: + version: ${{ env.GORELEASER_VERSION }} + install-only: true + - name: Initialize CodeQL + uses: github/codeql-action/init@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10 + with: + languages: go + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10 diff --git a/.github/workflows/dependency-review.yaml b/.github/workflows/dependency-review.yaml new file mode 100644 index 0000000..eab578c --- /dev/null +++ b/.github/workflows/dependency-review.yaml @@ -0,0 +1,27 @@ +name: Dependency Review +on: + pull_request: + branches: + - main + paths-ignore: + - "**/*.md" + - docs/** + - examples/** + +jobs: + dependency-review: + name: Dependencies Review + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout Repository + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + with: + show-progress: false + - name: Dependency Review + uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4 + with: + fail-on-scope: runtime,development,unknown + comment-summary-in-pr: on-failure diff --git a/.gitignore b/.gitignore index 01470c0..25afb1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,127 @@ -*.DS_Store -.idea -.vscode -*.env -*.log* -data-connector-agent -coverage.out +# Custom gitignore rules + +bin/ +coverage.txt + +# End of Custom gitignore rules + +# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,linux,windows,macos,go +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,linux,windows,macos,go + +### Go ### +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,linux,windows,macos,go diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 18f788a..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,13 +0,0 @@ -include: - - file: "/build/golang/template-app-go.yml" - project: "platform/pipelines-templates" - ref: "master" - - file: "/build/golang/template-app-go-test-latest.yml" - project: "platform/pipelines-templates" - ref: "master" - -default: - image: golang:1.20.1 - -variables: - IMAGE_NAME: white-lab/data-connector-agent diff --git a/.go-version b/.go-version new file mode 100644 index 0000000..14bee92 --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.23.2 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..f2d7afb --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,98 @@ +run: + timeout: 10m + build-tags: + - conformance + - integration + +linters: + disable-all: true + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - copyloopvar + - decorder + - dogsled + - durationcheck + - errcheck + - errname + - fatcontext + - goconst + - gocritic + - gocyclo + - gofmt + - goheader + - goimports + - mnd + - gosec + - gosimple + - gosmopolitan + - govet + - ineffassign + - misspell + - nolintlint + - prealloc + - predeclared + - revive + - staticcheck + - tagliatelle + - tenv + - thelper + - unconvert + - unparam + - unused + - usestdlibvars + - whitespace + - zerologlint +linters-settings: + gocyclo: + min-complexity: 15 + gofmt: + simplify: true + goconst: + ignore-tests: true + tagliatelle: + case: + use-field-name: true + rules: + yaml: camel + tenv: + all: true + unparam: + check-exported: false + mnd: + checks: + - case + - condition + - return + goheader: + values: + const: + MY COMPANY: Mia srl + template: |- + Copyright {{ MY COMPANY }} + SPDX-License-Identifier: Apache-2.0 + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +issues: + exclude-rules: + - path: zz_generated + linters: + - goimports + - path: _test\.go + linters: + - errcheck + - gosec + - tagliatelle diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..9745a02 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,54 @@ +version: 2 +dist: bin + +builds: +- main: "{{ .Env.BUILD_PATH }}" + binary: >- + {{ .Os }}/ + {{- .Arch }}/ + {{- with .Arm }}v{{ . }}/{{ end }} + {{- .ProjectName }} + no_unique_dist_dir: true + env: + - CGO_ENABLED=0 + flags: + - -trimpath + ldflags: + - -s + - -w + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + +archives: +- format: binary + name_template: >- + {{ .Binary }}- + {{- .Os }}- + {{- .Arch }}{{ with .Arm }}v{{ . }}{{ end }} + {{- with .Mips }}-{{ . }}{{ end }} + {{- if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }} + +checksum: + name_template: checksums.txt + +snapshot: + version_template: "{{ .ShortCommit }}" + +changelog: + sort: asc + groups: + - title: Features + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 0 + - title: Bug Fixes + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 1 + - title: Others + order: 999 + +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..04f7511 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,24 @@ +default: true +MD003: + style: atx +MD010: false +MD013: + line_length: 120 + heading_line_length: 80 + code_blocks: false + tables: false + headings: true + strict: false + stern: false +MD024: + siblings_only: true +MD029: + style: one +MD033: + allowed_elements: + - center + - picture + - source + - img +MD046: + style: fenced diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..32c25c7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,36 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: local + hooks: + - id: run-lint + name: Run make lint + entry: make lint + language: system + pass_filenames: false + - id: run-tests + name: Run make test + entry: make test + language: system + pass_filenames: false +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-case-conflict + name: Check filename case conflicts + - id: check-merge-conflict + name: Check that no merge conflict marker exists + - id: check-executables-have-shebangs + name: Check that executable files have shebangs + - id: check-shebang-scripts-are-executable + name: Check that files with shebangs are executable + - id: end-of-file-fixer + name: Makes sure files end in a newline and only a newline + - id: trailing-whitespace + name: Trims trailing whitespace + args: [--markdown-linebreak-ext=md] # add exception for markdown linebreaks +- repo: https://github.com/gitleaks/gitleaks + rev: v8.21.0 + hooks: + - id: gitleaks + name: Protect and discover secrets using Gitleaks diff --git a/CHANGELOG.md b/CHANGELOG.md index 059fac5..15a61af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ -# CHANGELOG +# Changelog All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## [Unreleased] diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index a18c8ec..3473142 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,78 +2,132 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to make participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, sex characteristics, gender identity and expression, -level of experience, education, socio-economic status, nationality, personal -appearance, race, religion, or sexual identity and orientation. +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to creating a positive environment -include: +Examples of behavior that contributes to a positive environment for our +community include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community -Examples of unacceptable behavior by participants include: +Examples of unacceptable behavior include: -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission +* Publishing others' private information, such as a physical or email address, + without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting -## Our Responsibilities +## Enforcement Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. ## Scope -This Code of Conduct applies within all project spaces, and it also applies when -an individual is representing the project or its community in public spaces. -Examples of representing a project or community include using an official -project e-mail address, posting via an official social media account, or acting -as an appointed representative at an online or offline event. Representation of -a project may be further defined and clarified by project maintainers. +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official email address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at [report@mia-platform.eu][mailto]. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. +reported to the community leaders responsible for enforcement at +[report@mia-platform.eu]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct.html][coc] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. -For answers to common questions about this code of conduct, see -[https://www.contributor-covenant.org/faq][faq] +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org -[coc]: https://www.contributor-covenant.org/version/1/4/code-of-conduct.html -[faq]: https://www.contributor-covenant.org/faq -[mailto]: mailto:report@mia-pltaform.eu +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations +[report@mia-platform.eu]: mailto:report@mia-platform.eu diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e880d5..5209aa3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,33 +1,55 @@ -# Contribution Guidelines - -First off, thank you for considering contributing to this project. - -Please follow these guidelines for helping us to better address your issue, assessing changes, and helping you finalize your pull requests. -There are many ways to contribute, from writing examples, improving the documentation, submitting bug reports -and feature requests or writing code which can be incorporated into the module itself. - -## Code of Conduct - -This project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md), please read it and follow it -before contributing. If you find someone that is not respecting it please report its behaviour. - -## How Can I Contribute - -### Reporting Bugs - -Before reporting a bug please search if there isn’t already a similar issue already open. If you find a similar issue -that is already closed, open a new one and include a link to it inside the body of the new one. - -### Propose a New Feature - -Before starting to implement a new feature, open the relative issue for starting an open discussion on where is can be -relevant and expose alternative solutions or potential pitfall that you can encounter. Fill all the information required -by the template. - -## Fork - -If you want to fork our project, you could make it and keep in sync with our template. -All contribution which could improve the existent code base are welcome! - -To keep a fork up to date, you can follow this [GitHub guide](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork). -For all the information about forks, [see this link](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks). +# Contributing + +We welcome contributions from the community. Please read the following guidelines carefully to +maximize the chances of your PR being merged. + +## Communication + +- If you want to work on some open issue, please reach out to us via a comment on it before starting your work to + check if someone else is already working on it. +- Before working on a new feature please open an issue for the feature request and partecipate in the discussion for + reaching an agreement on its design and utility for the project. +- Small patches, bug fixes and documentation typos fixing don’t need prior communication. + +## Inclusive Language + +Every PR, issue, code and documentation must be inclusive to all and must adhere to the following guidance: + +- Every documentation should follow an inclusive style. A nice writeup has been done by google in its [Google Developer + Documentation Style Guide]. +- Every contribution will be covered by our [Code of Conduct](./CODE_OF_CONDUCT.md) so read it carefully. +- We will follow and will amend this list with the best practice and guidance that will emerge in the industry in the + future and more comments and correction can be made during review by the mantainers. + +## Opening a PR + +- Fork the repo +- Read the [README.md](./README.md) file and the others documentation files, if presents, for guidances on how to setup + the project locally and running the tests. +- If your PR is adding codes it must also contains test that will cover it, try to cover 100% of your added code if + possibile. During the review be ready to explain why you cannot reach that percentage. +- We will not merge PR with failing tests or that will lower the coverage of the existing ones. +- When you open a PR please follow the indication that are provided in the template and provide all the relevant + information +- Your PR title should be descriptive. +- If your PR is co-authored or based on an earlier PR from another contributor, + please attribute them with `Co-authored-by: name `. + See [GitHub’s multiple author guidance] for further details. + +## Commit Message Styling + +Every commit in this repository must follow the guidelines provided by [Conventional commits]. +The following *types* are allowed: + +1. `fix:` a commit that fixes a bug. +1. `feat:` a commit that adds new functionality. +1. `docs:` a commit that adds or improves the documentation. +1. `test:` a commit that adds unit tests. +1. `ci:` a commit that improves the pipelines or the integration mechanisms. +1. `style:` a commit that changes the code or documentation format and/or style without modifying the implementation. +1. `chore:` a catch-all type for any other commits. Generally used for commits that do not add or improve + functionalities to code or documentation. + +[Google Developer Documentation Style Guide]: https://developers.google.com/style/inclusive-documentation +[GitHub’s multiple author guidance]: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors +[Conventional commits]: https://www.conventionalcommits.org/en/v1.0.0/ diff --git a/Dockerfile b/Dockerfile index 93111ad..6425e00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,21 @@ -############################ -# STEP 1 build executable binary -############################ -FROM golang:1.22 AS builder +# syntax=docker/dockerfile:1 +FROM docker.io/library/alpine:3.20.3@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d AS builder -WORKDIR /app - -COPY go.mod . -COPY go.sum . - -RUN go mod download -RUN go mod verify - -COPY . . - -RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -ldflags="-w -s" -o main . - -WORKDIR /app/build +ARG TARGETPLATFORM -RUN cp -r /app/main /app/LICENSE . +WORKDIR /app -############################ -# STEP 2 build service image -############################ +COPY bin/${TARGETPLATFORM}/data-integration-agent . +COPY LICENSE . FROM scratch -ARG COMMIT_SHA= - -LABEL maintainer="davide.bianchi@mia-platform.eu" \ - name="data-connector-agent" \ - description="This is the best template to start creating a service in Go integrated inside the Platform" \ - eu.mia-platform.url="https://www.mia-platform.eu" \ - vcs.sha="$COMMIT_SHA" - -ENV SERVICE_VERSION="0.0.0" - -# Import the user and group files from the builder. -COPY --from=builder /etc/passwd /etc/passwd # Import the certs from the builder. COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -WORKDIR /app - -COPY --from=builder /app/build/* ./ +COPY --from=builder /app /app # Use an unprivileged user. USER 1000 -CMD ["/app/main"] +CMD ["/app/data-integration-agent"] diff --git a/LICENSE b/LICENSE index 9a27cdf..261eeb9 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [2021] [Mia-Platform] + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -198,4 +198,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/Makefile b/Makefile index 62a5b2d..380dd52 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,75 @@ -VERSION ?= latest +# Copyright Mia srl +# SPDX-License-Identifier: Apache-2.0 -# Create a variable that contains the current date in UTC -# Different flow if this script is running on Darwin or Linux machines. -ifeq (Darwin,$(shell uname)) - NOW_DATE = $(shell date -u +%d-%m-%Y) +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DEBUG_MAKEFILE?= +ifeq ($(DEBUG_MAKEFILE),1) +$(warning ***** executing goal(s) "$(MAKECMDGOALS)") +$(warning ***** $(shell date)) else - NOW_DATE = $(shell date -u -I) +# If we're not debugging the Makefile, always hide the commands inside the goals +MAKEFLAGS+= -s endif -all: test +# It's necessary to set this because some environments don't link sh -> bash. +# Using env is more portable than setting the path directly +SHELL:= /usr/bin/env bash + +.EXPORT_ALL_VARIABLES: + +.SUFFIXES: + +## Set all variables +ifeq ($(origin PROJECT_DIR),undefined) +PROJECT_DIR:= $(abspath $(shell pwd -P)) +endif + +ifeq ($(origin OUTPUT_DIR),undefined) +OUTPUT_DIR:= $(PROJECT_DIR)/bin +endif + +ifeq ($(origin TOOLS_DIR),undefined) +TOOLS_DIR:= $(PROJECT_DIR)/tools +endif + +ifeq ($(origin TOOLS_BIN),undefined) +TOOLS_BIN:= $(TOOLS_DIR)/bin +endif + +# Set here the name of the package you want to build +CMDNAME:= REPO_NAME +BUILD_PATH:= . +CONFORMANCE_TEST_PATH:= $(PROJECT_DIR)/tests/e2e + +# enable modules +GO111MODULE:= on +GOOS:= $(shell go env GOOS) +GOARCH:= $(shell go env GOARCH) +GOARM:= $(shell go env GOARM) + +# Add additional targets that you want to run when calling make without arguments +.PHONY: all +all: build + +## Includes +include tools/make/clean.mk +include tools/make/lint.mk +include tools/make/test.mk +include tools/make/build.mk -.PHONY: test -test: - go test ./... -coverprofile coverage.out +# Uncomment the correct test suite to run during CI +.PHONY: ci +ci: test-coverage -.PHONY: version -version: - sed -i.bck "s|SERVICE_VERSION=\"[0-9]*.[0-9]*.[0-9]*.*\"|SERVICE_VERSION=\"${VERSION}\"|" "Dockerfile" - rm -fr "Dockerfile.bck" - git add "Dockerfile" - git commit -m "bump v${VERSION}" - git tag v${VERSION} +### Put your custom import, define or goals under here ### diff --git a/README.md b/README.md index 5b913bf..16cd080 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ # data-connector-agent -This is a simple Go application template with a pre-configured [logger]("https://github.com/mia-platform/glogger") and a [library]("https://github.com/mia-platform/configlib") to handle configuration file and env variables. +This is a simple Go application template with a pre-configured [logger] and a +[library] to handle configuration file and env variables. It also contains basic dependencies for testing and http request. By default the module name is "service", if you want to change it, please remember to change it in the imports too. ## Development Local To develop the service locally you need: - - Go 1.20+ + - Go 1.23+ To start the application locally @@ -22,5 +23,8 @@ By default the service will run on port 8080, to change the port please set `HTT To test the application use: ```go -go test -v +make test ``` + +[logger]: https://github.com/mia-platform/glogger +[library]: https://github.com/mia-platform/configlib diff --git a/config/env.go b/config/env.go index 02c7907..4b0d8dd 100644 --- a/config/env.go +++ b/config/env.go @@ -1,18 +1,17 @@ -/* - * Copyright 2019 Mia srl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright Mia srl +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package config diff --git a/go.mod b/go.mod index 7d5423e..175f1b5 100644 --- a/go.mod +++ b/go.mod @@ -1,41 +1,43 @@ module data-connector-agent -go 1.22 +go 1.23.2 require ( github.com/caarlos0/env/v10 v10.0.0 - github.com/davidebianchi/gswagger v0.9.0 - github.com/getkin/kin-openapi v0.115.0 - github.com/gofiber/fiber/v2 v2.49.1 - github.com/mia-platform/glogger/v4 v4.1.0 + github.com/davidebianchi/gswagger v0.10.0 + github.com/getkin/kin-openapi v0.128.0 + github.com/gofiber/fiber/v2 v2.52.5 + github.com/mia-platform/glogger/v4 v4.2.0 github.com/sirupsen/logrus v1.9.3 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 ) require ( - github.com/andybalholm/brotli v1.0.5 // indirect + github.com/andybalholm/brotli v1.1.0 // indirect + github.com/bahlo/generic-list-go v0.2.0 // indirect + github.com/buger/jsonparser v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/ghodss/yaml v1.0.0 // indirect - github.com/go-openapi/jsonpointer v0.19.5 // indirect - github.com/go-openapi/swag v0.21.1 // indirect - github.com/google/uuid v1.3.1 // indirect - github.com/iancoleman/orderedmap v0.2.0 // indirect - github.com/invopop/yaml v0.2.0 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/swag v0.23.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/invopop/jsonschema v0.12.0 // indirect + github.com/invopop/yaml v0.3.1 // indirect github.com/josharian/intern v1.0.0 // indirect - github.com/klauspost/compress v1.16.7 // indirect + github.com/klauspost/compress v1.17.6 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/mia-platform/jsonschema v0.1.0 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect - github.com/perimeterx/marshmallow v1.1.4 // indirect + github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.50.0 // indirect + github.com/valyala/fasthttp v1.52.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/sys v0.11.0 // indirect + github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect + golang.org/x/sys v0.17.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 142f4f5..644e58f 100644 --- a/go.sum +++ b/go.sum @@ -1,110 +1,92 @@ -github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= -github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= +github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= +github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/caarlos0/env/v10 v10.0.0 h1:yIHUBZGsyqCnpTkbjk8asUlx6RFhhEs+h7TOBdgdzXA= github.com/caarlos0/env/v10 v10.0.0/go.mod h1:ZfulV76NvVPw3tm591U4SwL3Xx9ldzBP9aGxzeN7G18= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/davidebianchi/gswagger v0.9.0 h1:wztdl5oSQ0PGgrbhivPr71VNIf4QUKQCeOffbd6lnTE= -github.com/davidebianchi/gswagger v0.9.0/go.mod h1:Ge69aGQIAWZs63UzaStPfqGT5u/gEXLsQ6vTM3gzDCE= -github.com/getkin/kin-openapi v0.115.0 h1:c8WHRLVY3G8m9jQTy0/DnIuljgRwTCB5twZytQS4JyU= -github.com/getkin/kin-openapi v0.115.0/go.mod h1:l5e9PaFUo9fyLJCPGQeXI2ML8c3P8BHOEV2VaAVf/pc= +github.com/davidebianchi/gswagger v0.10.0 h1:RrFeWwjAAewWNm3x4kqFzbg+KGZ5Ak2FRdOdY72ZJe8= +github.com/davidebianchi/gswagger v0.10.0/go.mod h1:2Lra+xPka3Vu/FFvh24LgqfRPpbay5uFSffVKET5D5A= +github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4= +github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= -github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU= -github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= -github.com/gofiber/fiber/v2 v2.49.1 h1:0W2DRWevSirc8pJl4o8r8QejDR8TV6ZUCawHxwbIdOk= -github.com/gofiber/fiber/v2 v2.49.1/go.mod h1:nPUeEBUeeYGgwbDm59Gp7vS8MDyScL6ezr/Np9A13WU= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA= -github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA= -github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA= -github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= -github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY= -github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= +github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo= +github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI= +github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0= +github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso= +github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= +github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mia-platform/glogger/v4 v4.1.0 h1:rqs4/qwfe7j7VyLEtZG++xpVpM+XOdlZlq7f/YHbj2Y= -github.com/mia-platform/glogger/v4 v4.1.0/go.mod h1:0Dqqthkv2jWdeoyghPIaMEKSWu+vyjSLQ85wfgNWEYs= -github.com/mia-platform/jsonschema v0.1.0 h1:tjQf7TaYROsAqk7SXTL+44TrfKk3bSEvhRGPS51IA5Y= -github.com/mia-platform/jsonschema v0.1.0/go.mod h1:r2DJjPA/+6S+WPnXZt1xONMvO2b4hlhfXfUYV0po/Dk= +github.com/mia-platform/glogger/v4 v4.2.0 h1:p4dhcYfHE5+5jIa2/r6B3Bk7q/1qvfe5H7YiJvdLlUM= +github.com/mia-platform/glogger/v4 v4.2.0/go.mod h1:pdFh/+B09Gup8KH3HSeWlV9tHn1ndCMZ7tdsQjIFRKw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/perimeterx/marshmallow v1.1.4 h1:pZLDH9RjlLGGorbXhcaQLhfuV0pFMNfPO55FuFkxqLw= -github.com/perimeterx/marshmallow v1.1.4/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= +github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= +github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= 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/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -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/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= -github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= +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= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e9M= -github.com/valyala/fasthttp v1.50.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= +github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0= +github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= +github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 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/main.go b/main.go index 4d0dac2..21159cc 100644 --- a/main.go +++ b/main.go @@ -1,18 +1,17 @@ -/* - * Copyright 2019 Mia srl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright Mia srl +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package main diff --git a/main_test.go b/main_test.go index f5110f6..f850315 100644 --- a/main_test.go +++ b/main_test.go @@ -1,18 +1,17 @@ -/* - * Copyright 2019 Mia srl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright Mia srl +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package main @@ -41,6 +40,10 @@ func TestEntryPoint(t *testing.T) { time.Sleep(1 * time.Second) resp, err := http.DefaultClient.Get("http://localhost:3000/-/healthz") + if resp.Body != nil { + resp.Body.Close() + } + require.Equal(t, nil, err) require.Equal(t, 200, resp.StatusCode) }) @@ -59,6 +62,10 @@ func TestEntryPoint(t *testing.T) { time.Sleep(1 * time.Second) resp, err := http.DefaultClient.Get("http://localhost:8080/prefix/") + if resp.Body != nil { + resp.Body.Close() + } + require.Equal(t, nil, err) require.Equal(t, 404, resp.StatusCode) }) diff --git a/router.go b/router.go index 9818805..6fd5029 100644 --- a/router.go +++ b/router.go @@ -1,18 +1,17 @@ -/* - * Copyright 2019 Mia srl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright Mia srl +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package main diff --git a/router_test.go b/router_test.go index f8e9c4d..b096dbd 100644 --- a/router_test.go +++ b/router_test.go @@ -1,3 +1,18 @@ +// Copyright Mia srl +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package main import ( @@ -28,8 +43,9 @@ func TestSetupRouter(t *testing.T) { request := httptest.NewRequest(http.MethodGet, "/documentations/json", nil) response, err := app.Test(request) require.NoError(t, err) - require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200") + defer response.Body.Close() + require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200") body, readBodyError := io.ReadAll(response.Body) require.NoError(t, readBodyError) require.True(t, string(body) != "", "The response body should not be an empty string") @@ -39,8 +55,9 @@ func TestSetupRouter(t *testing.T) { request := httptest.NewRequest(http.MethodGet, "/documentations/yaml", nil) response, err := app.Test(request) require.NoError(t, err) - require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200") + defer response.Body.Close() + require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200") body, readBodyError := io.ReadAll(response.Body) require.NoError(t, readBodyError) require.True(t, string(body) != "", "The response body should not be an empty string") diff --git a/statusroutes.go b/statusroutes.go index e6070e0..b064522 100644 --- a/statusroutes.go +++ b/statusroutes.go @@ -1,18 +1,17 @@ -/* - * Copyright 2019 Mia srl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright Mia srl +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package main diff --git a/statusroutes_test.go b/statusroutes_test.go index c180501..e1a63a6 100644 --- a/statusroutes_test.go +++ b/statusroutes_test.go @@ -1,3 +1,18 @@ +// Copyright Mia srl +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package main import ( @@ -22,7 +37,9 @@ func TestStatusRoutes(t *testing.T) { request := httptest.NewRequest(http.MethodGet, "/-/healthz", nil) response, err := app.Test(request) require.NoError(t, err) - require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200") + + defer response.Body.Close() + require.Equal(t, http.StatusOK, response.StatusCode, "The response statusCode should be 200") body, readBodyError := io.ReadAll(response.Body) require.NoError(t, readBodyError) require.Equal(t, expectedResponse, string(body), "The response body should be the expected one") @@ -33,7 +50,9 @@ func TestStatusRoutes(t *testing.T) { request := httptest.NewRequest(http.MethodGet, "/-/ready", nil) response, err := app.Test(request) require.NoError(t, err) - require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200") + + defer response.Body.Close() + require.Equal(t, http.StatusOK, response.StatusCode, "The response statusCode should be 200") body, readBodyError := io.ReadAll(response.Body) require.NoError(t, readBodyError) require.Equal(t, expectedResponse, string(body), "The response body should be the expected one") @@ -44,7 +63,9 @@ func TestStatusRoutes(t *testing.T) { request := httptest.NewRequest(http.MethodGet, "/-/check-up", nil) response, err := app.Test(request) require.NoError(t, err) - require.Equal(t, fiber.StatusOK, response.StatusCode, "The response statusCode should be 200") + + defer response.Body.Close() + require.Equal(t, http.StatusOK, response.StatusCode, "The response statusCode should be 200") body, readBodyError := io.ReadAll(response.Body) require.NoError(t, readBodyError) require.Equal(t, expectedResponse, string(body), "The response body should be the expected one") diff --git a/tools/GOLANGCI_LINT_VERSION b/tools/GOLANGCI_LINT_VERSION new file mode 100644 index 0000000..137ade0 --- /dev/null +++ b/tools/GOLANGCI_LINT_VERSION @@ -0,0 +1 @@ +v1.61.0 diff --git a/tools/GORELEASER_VERSION b/tools/GORELEASER_VERSION new file mode 100644 index 0000000..f706a60 --- /dev/null +++ b/tools/GORELEASER_VERSION @@ -0,0 +1 @@ +v2.3.2 diff --git a/tools/make/build.mk b/tools/make/build.mk new file mode 100644 index 0000000..da57b76 --- /dev/null +++ b/tools/make/build.mk @@ -0,0 +1,58 @@ +# Copyright Mia srl +# SPDX-License-Identifier: Apache-2.0 + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##@ Go Builds Goals + +.PHONY: build +build: + +# if not already installed in the system install a pinned version in tools folder +GORELEASER_PATH:= $(shell command -v goreleaser 2> /dev/null) +ifndef GORELEASER_PATH +GORELEASER_PATH:= $(TOOLS_BIN)/goreleaser +endif + +.PHONY: go/build/% +go/build/%: + $(eval OS:= $(word 1,$(subst /, ,$*))) + $(eval ARCH:= $(word 2,$(subst /, ,$*))) + $(eval ARM:= $(word 3,$(subst /, ,$*))) + $(info Building image for $(OS) $(ARCH) $(ARM)) + + GOOS=$(OS) GOARCH=$(ARCH) GOARM=$(ARM) $(GORELEASER_PATH) build \ + --single-target --snapshot --clean --config=.goreleaser.yaml + +.PHONY: go/build/multiarch +go/build/multiarch: + $(GORELEASER_PATH) build --snapshot --clean --config=.goreleaser.yaml + +.PHONY: build-deps +build-deps: + +build-deps: $(GORELEASER_PATH) + +build: build-deps + +.PHONY: build-multiarch +build-multiarch: $(GORELEASER_PATH) go/build/multiarch + +.PHONY: build +build: go/build/$(GOOS)/$(GOARCH)/$(GOARM) + +$(TOOLS_BIN)/goreleaser: $(TOOLS_DIR)/GORELEASER_VERSION + $(eval GORELEASER_VERSION:= $(shell cat $<)) + mkdir -p $(TOOLS_BIN) + $(info Installing goreleaser $(GORELEASER_VERSION) bin in $(TOOLS_BIN)) + GOBIN=$(TOOLS_BIN) go install github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION) diff --git a/tools/make/clean.mk b/tools/make/clean.mk new file mode 100644 index 0000000..74b019f --- /dev/null +++ b/tools/make/clean.mk @@ -0,0 +1,44 @@ +# Copyright Mia srl +# SPDX-License-Identifier: Apache-2.0 + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##@ Lint Goals + +.PHONY: clean +clean: + +.PHONY: clean/coverage +clean: clean/coverage +clean/coverage: + $(info Clean coverage file...) + rm -fr coverage.txt + +.PHONY: clean/bin +clean: clean/bin +clean/bin: + $(info Clean artifacts files...) + rm -fr $(OUTPUT_DIR) + +.PHONY: clean/tools +clean/tools: + $(info Clean tools folder...) + rm -fr $(TOOLS_BIN) + +.PHONY: clean/go +clean/go: + $(info Clean golang cache...) + go clean -cache + +.PHONY: clean-all +clean-all: clean clean/tools clean/go diff --git a/tools/make/lint.mk b/tools/make/lint.mk new file mode 100644 index 0000000..8501683 --- /dev/null +++ b/tools/make/lint.mk @@ -0,0 +1,56 @@ +# Copyright Mia srl +# SPDX-License-Identifier: Apache-2.0 + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##@ Lint Goals + +GOLANGCI_LINT_MODE?= colored-line-number + +# if not already installed in the system install a pinned version in tools folder +GOLANGCI_PATH:= $(shell command -v golangci-lint 2> /dev/null) +ifndef GOLANGCI_PATH + GOLANGCI_PATH:=$(TOOLS_BIN)/golangci-lint +endif + +.PHONY: lint +lint: + +.PHONY: lint-deps +lint-deps: + +.PHONY: golangci-lint +lint: golangci-lint +golangci-lint: $(GOLANGCI_PATH) + $(info Running golangci-lint with .golangci.yaml config file...) + $(GOLANGCI_PATH) run --out-format=$(GOLANGCI_LINT_MODE) --config=.golangci.yaml + +lint-deps: $(GOLANGCI_PATH) +$(TOOLS_BIN)/golangci-lint: $(TOOLS_DIR)/GOLANGCI_LINT_VERSION + $(eval GOLANGCI_LINT_VERSION:= $(shell cat $<)) + mkdir -p $(TOOLS_BIN) + $(info Installing golangci-lint $(GOLANGCI_LINT_VERSION) bin in $(TOOLS_BIN)) + GOBIN=$(TOOLS_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) + +.PHONY: gomod-lint +lint: gomod-lint +gomod-lint: + $(info Running go mod tidy) +# Always keep this version to latest -1 version of Go + go mod tidy -compat=1.20 + +.PHONY: ci-lint +ci-lint: lint +# Block the lint during ci if the go.mod and go.sum will be changed by go mod tidy + git diff --exit-code go.mod; + git diff --exit-code go.sum; diff --git a/tools/make/test.mk b/tools/make/test.mk new file mode 100644 index 0000000..bd2b5d1 --- /dev/null +++ b/tools/make/test.mk @@ -0,0 +1,45 @@ +# Copyright Mia srl +# SPDX-License-Identifier: Apache-2.0 + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##@ Go Tests Goals + +DEBUG_TEST?= +ifeq ($(DEBUG_TEST),1) +GO_TEST_DEBUG_FLAG:= -v +else +GO_TEST_DEBUG_FLAG:= +endif + +.PHONY: test/unit +test/unit: + $(info Running tests...) + go test $(GO_TEST_DEBUG_FLAG) -race ./... + +.PHONY: test/coverage +test/coverage: + $(info Running tests with coverage on...) + go test $(GO_TEST_DEBUG_FLAG) -race -coverprofile=coverage.txt -covermode=atomic ./... + +test/show/coverage: + go tool cover -func=coverage.txt + +.PHONY: test +test: test/unit + +.PHONY: test-coverage +test-coverage: test/coverage + +.PHONY: show-coverage +show-coverage: test-coverage test/show/coverage