#8 delete cobra, add micro-config-flag #11

Merged
vtolstov merged 53 commits from kgorbunov/pkgdash:master into master 2024-04-02 22:54:17 +03:00
14 changed files with 25 additions and 27 deletions
Showing only changes of commit 8a85fce0a9 - Show all commits

View File

@ -1,6 +1,7 @@
.PHONY: build
build:
CGO_ENABLED=0 go build -o bin/app -mod=readonly git.unistack.org/unistack-org/pkgdash/cmd/pkgdash
GOWORK=off CGO_ENABLED=0 go build -o bin/pkgdash -mod=readonly git.unistack.org/unistack-org/pkgdash/cmd/pkgdash
GOWORK=off CGO_ENABLED=0 go build -o bin/pkgdashcli -mod=readonly git.unistack.org/unistack-org/pkgdash/cmd/pkgdashcli
.PHONY: buildcli
buildcli:

View File

@ -7,7 +7,7 @@ import (
"io/fs"
"net/http"
"time"
slog "go.unistack.org/micro/v4/logger/slog"
appconfig "git.unistack.org/unistack-org/pkgdash/internal/config"
"git.unistack.org/unistack-org/pkgdash/internal/database"
"git.unistack.org/unistack-org/pkgdash/internal/handler"
@ -21,7 +21,6 @@ import (
envconfig "go.unistack.org/micro-config-env/v4"
fileconfig "go.unistack.org/micro-config-file/v4"
vaultconfig "go.unistack.org/micro-config-vault/v4"
zlogger "go.unistack.org/micro-logger-zerolog/v4"
victoriameter "go.unistack.org/micro-meter-victoriametrics/v4"
httpsrv "go.unistack.org/micro-server-http/v4"
healthhandler "go.unistack.org/micro-server-http/v4/handler/health"
@ -54,7 +53,7 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger.DefaultLogger = zlogger.NewLogger(zlogger.ReportCaller(), logger.WithLevel(logger.DebugLevel), logger.WithCallerSkipCount(4))
logger.DefaultLogger = slog.NewLogger(logger.WithLevel(logger.DebugLevel))
if err := logger.DefaultLogger.Init(); err != nil {
logger.Fatal(ctx, "failed to init logger")
}

View File

@ -94,12 +94,11 @@ func pkgdashcli() {
for _, configDir := range configDirs {
for _, configFile := range configFiles {
logger.Info(ctx, fmt.Sprintf("path: %s", filepath.Join(configDir, configFile)))
c := fileconfig.NewConfig(
config.AllowFail(false),
config.Struct(cfg),
options.Codec(yamlcodec.NewCodec()),
fileconfig.Path(".gitea/pkgdashcli.yaml"),
fileconfig.Path(filepath.Join(configDir, configFile)),
)
err = c.Init(options.Context(ctx))
if err != nil {

View File

@ -89,7 +89,7 @@ func NewInitCommand() *cobra.Command {
options.Codec(yamlcodec.NewCodec()),
fileconfig.Path(".gitea/pkgdashcli.yaml"),
)
err = c.Init(options.Context(ctx))
err = c.Init()
if err != nil {
logger.Error(ctx, fmt.Sprintf("failed to init config: %v", err))
return err

View File

@ -17,18 +17,18 @@ func (h *Handler) CommentCreate(ctx context.Context, req *pb.CommentCreateReq, r
err := req.Validate()
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "validation error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}
var com *models.Comment
if com, err = h.store.CommentCreate(ctx, req); err != nil {
logger.Error(ctx, err)
if errors.Is(err, sql.ErrNoRows) {
httpsrv.SetRspCode(ctx, http.StatusNotFound)
return httpsrv.SetError(NewNotFoundError(err))
}
logger.Error(ctx, "comment create error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err))
}

View File

@ -16,17 +16,18 @@ func (h *Handler) CommentDelete(ctx context.Context, req *pb.CommentDeleteReq, r
err := req.Validate()
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}
if err = h.store.CommentDelete(ctx, req); err != nil {
logger.Error(ctx, err)
if errors.Is(err, sql.ErrNoRows) {
httpsrv.SetRspCode(ctx, http.StatusNotFound)
return httpsrv.SetError(NewNotFoundError(err))
}
logger.Error(ctx, "comment delete error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err))
}

View File

@ -15,14 +15,14 @@ func (h *Handler) CommentList(ctx context.Context, req *pb.CommentListReq, rsp *
err := req.Validate()
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}
comments, err := h.store.CommentList(ctx, req)
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "comment list error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err))
}

View File

@ -15,14 +15,14 @@ func (h *Handler) ModuleList(ctx context.Context, req *pb.ModuleListReq, rsp *pb
err := req.Validate()
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}
modules, err := h.store.ModuleList(ctx, req)
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "module list error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err))
}

View File

@ -14,14 +14,14 @@ func (h *Handler) PackageCreate(ctx context.Context, req *pb.PackageCreateReq, r
logger.Debug(ctx, "PackagesCreate handler start")
if err := req.Validate(); err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}
pkg, err := h.store.PackageCreate(ctx, req)
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "package create error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}

View File

@ -13,13 +13,13 @@ func (h *Handler) PackageDelete(ctx context.Context, req *pb.PackageDeleteReq, r
logger.Debug(ctx, "Start UpdatePackage")
if err := req.Validate(); err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}
if err := h.store.PackageDelete(ctx, req); err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "package delete error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err))
}

View File

@ -14,14 +14,14 @@ func (h *Handler) PackageLookup(ctx context.Context, req *pb.PackageLookupReq, r
logger.Debug(ctx, "Start PackagesLookup")
if err := req.Validate(); err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}
pkg, err := h.store.PackageLookup(ctx, req)
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "package lookup", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err))
}

View File

@ -14,14 +14,14 @@ func (h *Handler) PackageUpdate(ctx context.Context, req *pb.PackageUpdateReq, r
logger.Debug(ctx, "Start UpdatePackage")
if err := req.Validate(); err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err))
}
pkg, err := h.store.PackageUpdate(ctx, req)
if err != nil {
logger.Error(ctx, err)
logger.Error(ctx, "package update error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err))
}

View File

@ -25,9 +25,7 @@ import (
"go.unistack.org/micro/v4/logger"
)
var (
ErrPRNotExist = errors.New("pull request does not exist")
)
var ErrPRNotExist = errors.New("pull request does not exist")
type Gitea struct {
URL string

View File

@ -125,7 +125,7 @@ func parseModFile(ctx context.Context, store storage.Storage, pkg *models.Packag
err = tree.Files().ForEach(func(file *object.File) error {
if file == nil {
err = errors.New("file pointer is nil")
logger.Error(ctx, err)
logger.Error(ctx, "file tree error", err)
return err
}