Linter and Drone config fixes, code linting.

This commit is contained in:
2021-11-20 23:06:40 +05:00
parent 9c045e9fd3
commit d5fcc5cef9
22 changed files with 152 additions and 146 deletions

View File

@@ -1,10 +1,8 @@
package clientv1
import (
// stdlib
"strings"
// local
"go.dev.pztrn.name/giredore/internal/requester"
"go.dev.pztrn.name/giredore/internal/structs"
)

View File

@@ -1,17 +1,12 @@
package clientv1
import (
// local
"github.com/rs/zerolog"
"go.dev.pztrn.name/giredore/internal/logger"
"go.dev.pztrn.name/giredore/internal/requester"
// other
"github.com/rs/zerolog"
)
var (
log zerolog.Logger
)
var log zerolog.Logger
func Initialize() {
log = logger.Logger.With().Str("type", "domain").Str("package", "client").Int("version", 1).Logger()

View File

@@ -1,10 +1,8 @@
package clientv1
import (
// stdlib
"strings"
// local
"go.dev.pztrn.name/giredore/internal/requester"
"go.dev.pztrn.name/giredore/internal/structs"
)
@@ -29,6 +27,7 @@ func DeletePackage(args []string, options map[string]string) {
func GetPackages(args []string, options map[string]string) {
pkgs := strings.Split(args[0], ",")
// nolint:exhaustivestruct
req := &structs.PackageGetRequest{}
if pkgs[0] == "all" {
req.All = true

View File

@@ -1,32 +1,32 @@
package serverv1
import (
// stdlib
"net/http"
// local
"github.com/labstack/echo"
"go.dev.pztrn.name/giredore/internal/configuration"
"go.dev.pztrn.name/giredore/internal/structs"
// other
"github.com/labstack/echo"
)
// This function responsible for getting runtime configuration.
func configurationGET(ec echo.Context) error {
// nolint:wrapcheck
return ec.JSON(http.StatusOK, configuration.Cfg)
}
func configurationAllowedIPsSET(ec echo.Context) error {
func configurationAllowedIPsSET(ectx echo.Context) error {
// nolint:exhaustivestruct
req := &structs.AllowedIPsSetRequest{}
if err := ec.Bind(req); err != nil {
if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse allowed IPs set request")
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingAllowedIPsSetRequest}})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingAllowedIPsSetRequest}})
}
log.Debug().Msgf("Got set allowed IPs request: %+v", req)
configuration.Cfg.SetAllowedIPs(req.AllowedIPs)
return ec.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
}

View File

@@ -1,17 +1,12 @@
package serverv1
import (
// local
"github.com/rs/zerolog"
"go.dev.pztrn.name/giredore/internal/httpserver"
"go.dev.pztrn.name/giredore/internal/logger"
// other
"github.com/rs/zerolog"
)
var (
log zerolog.Logger
)
var log zerolog.Logger
func Initialize() {
log = logger.Logger.With().Str("type", "domain").Str("package", "server").Int("version", 1).Logger()

View File

@@ -1,43 +1,43 @@
package serverv1
import (
// stdlib
"net/http"
"strings"
// local
"github.com/labstack/echo"
"go.dev.pztrn.name/giredore/internal/configuration"
"go.dev.pztrn.name/giredore/internal/structs"
// other
"github.com/labstack/echo"
)
func throwGoImports(ec echo.Context) error {
func throwGoImports(ectx echo.Context) error {
// Getting real path. This might be the package itself, or namespace
// to list available packages.
// For now only package itself is supported, all other features in ToDo.
packageNameRaw := ec.Request().URL.Path
packageNameRaw := ectx.Request().URL.Path
pkgs, errs := configuration.Cfg.GetPackagesInfo([]string{packageNameRaw})
if errs != nil {
log.Error().Str("package", packageNameRaw).Msgf("Failed to get package information: %+v", errs)
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs})
}
if len(pkgs) == 0 {
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}})
}
pkg, found := pkgs[packageNameRaw]
if !found {
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}})
}
// We should compose package name using our domain under which giredore
// is working.
domain := ec.Request().Host
domain := ectx.Request().Host
packageName := domain + packageNameRaw
tmpl := singlePackageTemplate
@@ -45,5 +45,6 @@ func throwGoImports(ec echo.Context) error {
tmpl = strings.Replace(tmpl, "{VCS}", pkg.VCS, 1)
tmpl = strings.Replace(tmpl, "{REPOPATH}", pkg.RealPath, 1)
return ec.HTML(http.StatusOK, tmpl)
// nolint:wrapcheck
return ectx.HTML(http.StatusOK, tmpl)
}

View File

@@ -1,24 +1,23 @@
package serverv1
import (
// stdlib
"net/http"
"strings"
// local
"github.com/labstack/echo"
"go.dev.pztrn.name/giredore/internal/configuration"
"go.dev.pztrn.name/giredore/internal/structs"
// other
"github.com/labstack/echo"
)
// This function responsible for getting packages configuration.
func packagesGET(ec echo.Context) error {
func packagesGET(ectx echo.Context) error {
// nolint:exhaustivestruct
req := &structs.PackageGetRequest{}
if err := ec.Bind(req); err != nil {
if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package get request")
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingPackagesGetRequest}})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingPackagesGetRequest}})
}
log.Info().Msgf("Received package(s) info get request: %+v", req)
@@ -34,18 +33,23 @@ func packagesGET(ec echo.Context) error {
}
if len(errors) > 0 {
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errors, Data: pkgs})
// nolint:wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errors, Data: pkgs})
}
return ec.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess, Data: pkgs})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess, Data: pkgs})
}
// This function responsible for deleting package.
func packagesDELETE(ec echo.Context) error {
func packagesDELETE(ectx echo.Context) error {
// nolint:exhaustivestruct
req := &structs.PackageDeleteRequest{}
if err := ec.Bind(req); err != nil {
if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package delete request")
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingDeleteRequest}})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingDeleteRequest}})
}
log.Info().Msgf("Received package delete request: %+v", req)
@@ -53,28 +57,35 @@ func packagesDELETE(ec echo.Context) error {
errs := configuration.Cfg.DeletePackage(req)
if len(errs) > 0 {
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs})
}
return ec.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
}
// This function responsible for setting or updating packages.
func packagesSET(ec echo.Context) error {
func packagesSET(ectx echo.Context) error {
// nolint:exhaustivestruct
req := &structs.Package{}
if err := ec.Bind(req); err != nil {
if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package data")
return ec.JSON(http.StatusBadRequest, nil)
// nolint:wrapcheck
return ectx.JSON(http.StatusBadRequest, nil)
}
log.Info().Msgf("Received package set/update request: %+v", req)
// Validate passed package data.
if !strings.HasPrefix(req.OriginalPath, "/") {
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrPackageOrigPathShouldStartWithSlash}})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrPackageOrigPathShouldStartWithSlash}})
}
configuration.Cfg.AddOrUpdatePackage(req)
return ec.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
// nolint:exhaustivestruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
}