commit a6425232ec46a92d5c79b2e72dd415e7907d9ba1 Author: Dawid Wysokiński Date: Thu May 26 06:28:59 2022 +0200 init diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..298ec4a --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,54 @@ +name: PR checks +on: + push: + branches: + - master + pull_request: + +env: + GO_VERSION: 1.18.x + +jobs: + go-mod: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + - name: Check go mod + run: | + go mod tidy + git diff --exit-code go.mod + golangci-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.46 + + tests: + strategy: + matrix: + go: [ 1.18.x ] + platform: [ ubuntu-latest ] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v3 + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - name: Run go vet + run: go vet ./... + - name: Run go build + run: go build + - name: Run tests + run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..741ac8e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,44 @@ +run: + tests: true + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dupl + - errcheck + - gocritic + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - prealloc + - staticcheck + - structcheck + - typecheck + - unconvert + - unused + - varcheck + - lll + - nestif + - thelper + - nonamedreturns + +linters-settings: + lll: + line-length: 150 + +issues: + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - dupl + - linters: + - lll + source: "^//go:generate " diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..40bc7c1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2022 Dawid Wysokiński + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..31c1334 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/Kichiyaki/lubimyczytacrss + +go 1.18 diff --git a/main.go b/main.go new file mode 100644 index 0000000..764763a --- /dev/null +++ b/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "context" + "log" + "net/http" + "os" + "os/signal" + "time" +) + +func main() { + httpSrv := &http.Server{ + Addr: ":9234", + Handler: nil, + ReadTimeout: 2 * time.Second, + ReadHeaderTimeout: 2 * time.Second, + WriteTimeout: 2 * time.Second, + IdleTimeout: 2 * time.Second, + } + + go func(httpSrv *http.Server) { + if err := httpSrv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatalln("httpSrv.ListenAndServe:", err) + } + }(httpSrv) + + log.Println("Server is listening on the port 9234") + + ctxSignal, stop := signal.NotifyContext(context.Background(), os.Interrupt) + defer stop() + + <-ctxSignal.Done() + + ctxShutdown, cancelCtxShutdown := context.WithTimeout(context.Background(), 10*time.Second) + defer cancelCtxShutdown() + if err := httpSrv.Shutdown(ctxShutdown); err != nil { + log.Fatalln("httpSrv.Shutdown:", err) + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..c073fea --- /dev/null +++ b/renovate.json @@ -0,0 +1,7 @@ +{ + "extends": [ + "config:base", + ":semanticCommits", + ":semanticCommitTypeAll(chore)" + ] +}