This commit is contained in:
aespin 2024-10-02 13:40:27 +02:00
parent 1cb83dbde6
commit 49fb704bb1
4 changed files with 6 additions and 6 deletions

View File

@ -8,8 +8,8 @@ import (
"syscall"
"time"
"git.espin.casa/albert/cml04-falcon-system/handset/publisher"
"git.espin.casa/albert/cml04-falcon-system/handset/routes"
"git.espin.casa/albert/cml04-falcon-system/internal/publisher"
"git.espin.casa/albert/logger"
"github.com/julienschmidt/httprouter"
"github.com/nats-io/nats.go"

View File

@ -3,14 +3,14 @@ package handlers
import (
"net/http"
"git.espin.casa/albert/cml04-falcon-system/handset/publisher"
"git.espin.casa/albert/cml04-falcon-system/internal/publisher"
"github.com/julienschmidt/httprouter"
)
func BarCodeHandler(publisher publisher.Publisher) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
barcode := ps.ByName("barcode")
if err := publisher.Barcode(r.Context(), barcode); err != nil {
if err := publisher.NewBarcode(r.Context(), barcode); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

View File

@ -2,7 +2,7 @@ package routes
import (
"git.espin.casa/albert/cml04-falcon-system/handset/handlers"
"git.espin.casa/albert/cml04-falcon-system/handset/publisher"
"git.espin.casa/albert/cml04-falcon-system/internal/publisher"
"github.com/julienschmidt/httprouter"
)

View File

@ -10,14 +10,14 @@ import (
)
type Publisher interface {
Barcode(ctx context.Context, barcode string) error
NewBarcode(ctx context.Context, barcode string) error
}
type publisher struct {
nc *nats.Conn
}
func (e *publisher) Barcode(ctx context.Context, barcode string) error {
func (e *publisher) NewBarcode(ctx context.Context, barcode string) error {
// create event message
evt := cml04eventer.NewEvent("falcon-handset", "barcode.new", nil, []byte(barcode))
// create buffer message data