add worker with analyze go.mod(pref ver util)
This commit is contained in:
@@ -2,16 +2,16 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
cmsstorage "go.unistack.org/cms-service/storage"
|
||||
"go.unistack.org/micro/v3"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/unistack-org/pkgdash/config"
|
||||
pb "go.unistack.org/unistack-org/pkgdash/proto/go_generate"
|
||||
"go.unistack.org/unistack-org/pkgdash/service/client_git"
|
||||
"go.unistack.org/unistack-org/pkgdash/storage"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
@@ -21,6 +21,9 @@ type Handler struct {
|
||||
writer writer
|
||||
protojson.MarshalOptions
|
||||
protojson.UnmarshalOptions
|
||||
|
||||
git client_git.Client
|
||||
chanUrl chan *pb.AddPackageRsp
|
||||
}
|
||||
|
||||
func (h *Handler) ListPackage(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -42,12 +45,39 @@ func (h *Handler) ListPackage(w http.ResponseWriter, r *http.Request) {
|
||||
h.writer.Response(ctx, w, rsp)
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateInfo(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *Handler) UpdatePackage(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
logger := h.svc.Logger()
|
||||
logger.Debug(ctx, "Start UpdateInfo")
|
||||
logger.Debug(ctx, "Start UpdatePackage")
|
||||
|
||||
// TODO
|
||||
defer r.Body.Close()
|
||||
all, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
logger.Error(ctx, err)
|
||||
h.writer.Response(ctx, w, NewInternalError(err))
|
||||
return
|
||||
}
|
||||
|
||||
rsp := new(pb.UpdatePackageRsp)
|
||||
if err = h.Unmarshal(all, rsp); err != nil {
|
||||
logger.Error(ctx, err)
|
||||
h.writer.Response(ctx, w, NewUnmarshalError(err))
|
||||
return
|
||||
}
|
||||
|
||||
if err = rsp.Validate(); err != nil {
|
||||
logger.Error(ctx, err)
|
||||
h.writer.Response(ctx, w, NewValidationError(err))
|
||||
return
|
||||
}
|
||||
|
||||
if err = h.store.UpdatePackage(ctx, rsp); err != nil {
|
||||
logger.Error(ctx, err)
|
||||
h.writer.Response(ctx, w, NewInternalError(err))
|
||||
return
|
||||
}
|
||||
|
||||
logger.Debug(ctx, "Success finish UpdatePackage")
|
||||
}
|
||||
|
||||
func (h *Handler) AddComment(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -111,21 +141,24 @@ func (h *Handler) AddPackage(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// need logic for add module from go.mod
|
||||
// err := setModules(req)
|
||||
|
||||
if err = h.store.AddPackage(ctx, req); err != nil {
|
||||
logger.Error(ctx, err)
|
||||
h.writer.Response(ctx, w, NewInternalError(err))
|
||||
return
|
||||
if h.git.IsClose() {
|
||||
logger.Error(ctx, "chan is closed")
|
||||
} else {
|
||||
h.chanUrl <- req
|
||||
}
|
||||
|
||||
logger.Debug(ctx, "Success finish addPackage")
|
||||
}
|
||||
|
||||
func NewHandler(svc micro.Service, w writer) *Handler {
|
||||
return &Handler{svc: svc, writer: w}
|
||||
func NewHandler(svc micro.Service, w writer, client client_git.Client) *Handler {
|
||||
h := &Handler{
|
||||
svc: svc,
|
||||
writer: w,
|
||||
git: client,
|
||||
}
|
||||
h.EmitUnpopulated = true
|
||||
h.UseProtoNames = false
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *Handler) Init(ctx context.Context) error {
|
||||
@@ -138,6 +171,8 @@ func (h *Handler) Init(ctx context.Context) error {
|
||||
return errors.New(config.ServiceName, "error init storage", 1)
|
||||
}
|
||||
|
||||
h.chanUrl = h.git.Run(ctx, st)
|
||||
|
||||
h.store = st
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user