Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
euskadi31 committed Nov 28, 2024
1 parent 72d76ab commit db980bf
Show file tree
Hide file tree
Showing 43 changed files with 172 additions and 148 deletions.
21 changes: 5 additions & 16 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
Expand All @@ -32,20 +35,6 @@ jobs:
~/libvips-${{ matrix.libvips }}
key: ${{ runner.os }}-${{ matrix.libvips }}

- uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Install vips
shell: bash
run: .github/install_libvips.sh ${{ matrix.libvips }}
Expand Down Expand Up @@ -171,8 +160,8 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6.1.1
with:
version: v1.55.2
skip-pkg-cache: true
version: v1.62.2
skip-cache: true

- name: Coveralls
uses: shogo82148/actions-goveralls@v1
Expand Down
26 changes: 15 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
issues:
exclude-case-sensitive: false
exclude-dirs-use-default: true
exclude-files:
- .*_mock\.go
- mock_.*\.go
- .*/pkg/mod/.*$
- .*/go/src/.*\.go
exclude-generated: strict
exclude-use-default: true
max-issues-per-linter: 50
linters:
disable-all: true
enable:
- errcheck
- gas
- goconst
- gocyclo
- gofmt
- revive
- govet
- ineffassign
- megacheck
- misspell
- typecheck
- unconvert
Expand All @@ -22,7 +31,6 @@ linters:
- durationcheck
- errorlint
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- gocritic
Expand Down Expand Up @@ -60,9 +68,8 @@ linters-settings:
goimports:
local-prefixes: go.opentelemetry.io
govet:
check-shadowing: false
maligned:
suggest-new: true
disable:
- shadow
misspell:
ignore-words:
- cancelled
Expand All @@ -71,15 +78,12 @@ linters-settings:
ignore-generated-header: true
severity: warning
output:
format: colored-line-number
formats:
- format: colored-line-number
print-issued-lines: true
print-linter-name: true
run:
concurrency: 4
issues-exit-code: 1
skip-files:
- .*_mock\.go
- mock_.*\.go
- .*/pkg/mod/.*$
tests: false
timeout: 1m
7 changes: 4 additions & 3 deletions cmd/hyperpic/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ import (
"github.com/rs/zerolog/log"
)

// Run Hyperpic api server
// Run Hyperpic api server.
func Run() (err error) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)

_ = service.Get(container.LoggerKey)

router := service.Get(container.RouterKey).(*server.Server)
router := service.Get(container.RouterKey).(*server.Server) // nolint: forcetypeassert

log.Info().Msg("Rinning")

go func() {
log.Info().Msg("Rinning HTTP Router")

if e := router.Run(); e != nil {
log.Error().Err(e).Msg("server.Run() failed")

Expand All @@ -39,5 +40,5 @@ func Run() (err error) {

log.Info().Msg("Shutdown")

return router.Shutdown()
return router.Shutdown() // nolint: wrapcheck
}
2 changes: 1 addition & 1 deletion cmd/hyperpic/app/config/auth_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package config

// AuthConfiguration struct
// AuthConfiguration struct.
type AuthConfiguration struct {
Secret string
}
4 changes: 2 additions & 2 deletions cmd/hyperpic/app/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hyperscale/hyperpic/pkg/hyperpic/server"
)

// Configuration struct
// Configuration struct.
type Configuration struct {
Logger *logger.Configuration
Server *server.Configuration
Expand All @@ -19,7 +19,7 @@ type Configuration struct {
Doc *DocConfiguration
}

// NewConfiguration constructor
// NewConfiguration constructor.
func NewConfiguration() *Configuration {
return &Configuration{
Server: &server.Configuration{},
Expand Down
2 changes: 1 addition & 1 deletion cmd/hyperpic/app/config/doc_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package config

// DocConfiguration struct
// DocConfiguration struct.
type DocConfiguration struct {
Enable bool
}
2 changes: 1 addition & 1 deletion cmd/hyperpic/app/config/image_cache_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hyperscale/hyperpic/pkg/hyperpic/provider/memory"
)

// ImageCacheConfiguration struct
// ImageCacheConfiguration struct.
type ImageCacheConfiguration struct {
Provider string
FS *filesystem.CacheConfiguration
Expand Down
2 changes: 1 addition & 1 deletion cmd/hyperpic/app/config/image_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package config

// ImageConfiguration struct
// ImageConfiguration struct.
type ImageConfiguration struct {
Source *ImageSourceConfiguration
Cache *ImageCacheConfiguration
Expand Down
2 changes: 1 addition & 1 deletion cmd/hyperpic/app/config/image_source_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package config

import "github.com/hyperscale/hyperpic/pkg/hyperpic/provider/filesystem"

// ImageSourceConfiguration struct
// ImageSourceConfiguration struct.
type ImageSourceConfiguration struct {
MaxSize int64 `mapstructure:"max_size"`
Provider string
Expand Down
6 changes: 3 additions & 3 deletions cmd/hyperpic/app/config/image_support_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

package config

// ImageSupportConfiguration struct
// ImageSupportConfiguration struct.
type ImageSupportConfiguration struct {
Extensions map[string]interface{}
}

// IsExtSupported return true if ext is supported
// IsExtSupported return true if ext is supported.
func (c ImageSupportConfiguration) IsExtSupported(ext string) bool {
enable, ok := c.Extensions[ext]

return (ok && enable.(bool))
return (ok && enable.(bool)) // nolint: forcetypeassert
}
5 changes: 3 additions & 2 deletions cmd/hyperpic/app/container/config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (
"github.com/spf13/viper"
)

// Services keys
// Services keys.
const (
ConfigKey = "service.config"
)

const name = "hyperpic"

// nolint: forcetypeassert
func init() {
service.Set(ConfigKey, func(c service.Container) interface{} {
cmd := c.Get(FlagsKey).(*flag.FlagSet)
Expand Down Expand Up @@ -61,7 +62,7 @@ func init() {
options.SetDefault("image.cache.fs.clean_interval", "1h")
options.SetDefault("image.cache.memory.life_time", "24h")
options.SetDefault("image.cache.memory.clean_interval", "1h")
options.SetDefault("image.cache.memory.memory_limit", uint64(memory.TotalMemory()/2))
options.SetDefault("image.cache.memory.memory_limit", memory.TotalMemory()/2)
options.SetDefault("image.support.extensions", map[string]bool{
"jpg": true,
"jpeg": true,
Expand Down
3 changes: 2 additions & 1 deletion cmd/hyperpic/app/container/controller_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
"github.com/hyperscale/hyperpic/pkg/hyperpic/provider"
)

// Services keys
// Services keys.
const (
DocControllerKey = "service.controller.doc"
ImageControllerKey = "service.controller.image"
)

// nolint: forcetypeassert
func init() {
service.Set(DocControllerKey, func(c service.Container) interface{} {
return controller.NewDocController()
Expand Down
2 changes: 1 addition & 1 deletion cmd/hyperpic/app/container/flags_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/euskadi31/go-service"
)

// Services keys
// Services keys.
const (
FlagsKey = "service.flags"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/hyperpic/app/container/image_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hyperscale/hyperpic/pkg/hyperpic/image"
)

// Services keys
// Services keys.
const (
ImageOptionParserKey = "service.image.options.parser"
ImageProcessorKey = "service.image.processor"
Expand Down
3 changes: 2 additions & 1 deletion cmd/hyperpic/app/container/logger_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (
"github.com/rs/zerolog/log"
)

// Services keys
// Services keys.
const (
LoggerKey = "service.logger"
)

// nolint: forcetypeassert
func init() {
service.Set(LoggerKey, func(c service.Container) interface{} {
cfg := c.Get(ConfigKey).(*config.Configuration)
Expand Down
3 changes: 2 additions & 1 deletion cmd/hyperpic/app/container/provider_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"github.com/rs/zerolog/log"
)

// Services keys
// Services keys.
const (
CacheProviderKey = "service.provider.cache"
SourceProviderKey = "service.provider.source"
)

// nolint: forcetypeassert
func init() {
service.Set(CacheProviderKey, func(c service.Container) interface{} {
cfg := c.Get(ConfigKey).(*config.Configuration)
Expand Down
3 changes: 2 additions & 1 deletion cmd/hyperpic/app/container/router_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (
"github.com/rs/zerolog/hlog"
)

// Services keys
// Services keys.
const (
RouterKey = "service.http.router"
)

// nolint: forcetypeassert
func init() {
service.Set(RouterKey, func(c service.Container) interface{} {
cfg := c.Get(ConfigKey).(*config.Configuration)
Expand Down
8 changes: 4 additions & 4 deletions cmd/hyperpic/app/controller/doc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ import (
type docController struct {
}

// NewDocController func
// NewDocController func.
func NewDocController() server.Controller {
return &docController{}
}

// Mount endpoints
// Mount endpoints.
func (c docController) Mount(r *server.Router) {
r.AddRouteFunc("/docs/swagger.yaml", c.getSwaggerHandler).Methods(http.MethodGet)
r.AddRouteFunc("/docs/", c.getDocHandler).Methods(http.MethodGet)
}

// GET /docs/swagger.yaml
// GET /docs/swagger.yaml.
func (c docController) getSwaggerHandler(w http.ResponseWriter, r *http.Request) {
name := "swagger.yaml"

Expand All @@ -47,7 +47,7 @@ func (c docController) getSwaggerHandler(w http.ResponseWriter, r *http.Request)
)
}

// GET /docs/
// GET /docs/.
func (c docController) getDocHandler(w http.ResponseWriter, r *http.Request) {
name := "index.html"

Expand Down
Loading

0 comments on commit db980bf

Please sign in to comment.