Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example of interactive command-line messaging and top layer makefile #18

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
all: frontier examples

.PHONY: frontier
frontier:
go build -trimpath -ldflags "-s -w" -o ./frontier cmd/frontier/main.go

.PHONY: frontier-linux
frontier-linux:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o ./frontier cmd/frontier/main.go

#docker: linux
# docker build -t harbor.moresec.cn/moresec/ms_gw:1.4.0 .
# docker push harbor.moresec.cn/moresec/ms_gw:1.4.0

.PHONY: examples
examples:
make -C examples

.PHONY: clean
clean:
rm ./frontier
rm ./examples/iclm/iclm_edge
rm ./examples/iclm/iclm_service

.PHONY: output
output: build


6 changes: 3 additions & 3 deletions api/v1/service/service_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newServiceEnd(dialer client.Dialer, opts ...ServiceOption) (*serviceEnd, er

// Control Register
func (service *serviceEnd) RegisterGetEdgeID(ctx context.Context, getEdgeID GetEdgeID) error {
return service.End.Register(ctx, "get_edge_id", func(ctx context.Context, req geminio.Request, rsp geminio.Response) {
return service.End.Register(ctx, api.RPCGetEdgeID, func(ctx context.Context, req geminio.Request, rsp geminio.Response) {
id, err := getEdgeID(req.Data())
if err != nil {
// we just deliver the err back
Expand All @@ -73,7 +73,7 @@ func (service *serviceEnd) RegisterGetEdgeID(ctx context.Context, getEdgeID GetE
}

func (service *serviceEnd) RegisterEdgeOnline(ctx context.Context, edgeOnline EdgeOnline) error {
return service.End.Register(ctx, "edge_online", func(ctx context.Context, req geminio.Request, rsp geminio.Response) {
return service.End.Register(ctx, api.RPCEdgeOnline, func(ctx context.Context, req geminio.Request, rsp geminio.Response) {
on := &api.OnEdgeOnline{}
err := json.Unmarshal(req.Data(), on)
if err != nil {
Expand All @@ -91,7 +91,7 @@ func (service *serviceEnd) RegisterEdgeOnline(ctx context.Context, edgeOnline Ed
}

func (service *serviceEnd) RegisterEdgeOffline(ctx context.Context, edgeOffline EdgeOffline) error {
return service.End.Register(ctx, "edge_offline", func(ctx context.Context, req geminio.Request, rsp geminio.Response) {
return service.End.Register(ctx, api.RPCEdgeOffline, func(ctx context.Context, req geminio.Request, rsp geminio.Response) {
off := &api.OnEdgeOffline{}
err := json.Unmarshal(req.Data(), off)
if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions cmd/frontier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,33 @@ func main() {
klog.Errorf("parse flags err: %s", err)
return
}
klog.Infof("frontier starts")
defer func() {
klog.Infof("frontier ends")
klog.Flush()
}()

// dao
dao, err := dao.NewDao(conf)
if err != nil {
klog.Errorf("new dao err: %s", err)
return
}
klog.V(5).Infof("new dao succeed")
// mqm
mqm, err := mq.NewMQM(conf)
if err != nil {
klog.Errorf("new mq manager err: %s", err)
return
}
klog.V(5).Infof("new mq manager succeed")
// exchange
exchange, err := exchange.NewExchange(conf)
if err != nil {
klog.Errorf("new exchange err: %s", err)
return
}
klog.V(5).Infof("new exchange succeed")

tmr := timer.NewTimer()
// servicebound
Expand All @@ -46,18 +55,21 @@ func main() {
klog.Errorf("new servicebound err: %s", err)
return
}
servicebound.Serve()
go servicebound.Serve()
klog.V(5).Infof("new servicebound succeed")

// edgebound
edgebound, err := edgebound.NewEdgebound(conf, dao, nil, exchange, tmr)
if err != nil {
klog.Errorf("new edgebound err: %s", err)
return
}
edgebound.Serve()
go edgebound.Serve()
klog.V(5).Infof("new edgebound succeed")

sig := sigaction.NewSignal()
sig.Wait(context.TODO())

edgebound.Close()
servicebound.Close()
}
9 changes: 9 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GOHOSTOS?=$(shell go env GOHOSTOS)
GOARCH?=$(shell go env GOARCH)

.PHONY: all
all: iclm

.PHONY: iclm
iclm:
make -C iclm
17 changes: 17 additions & 0 deletions examples/iclm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GOHOSTOS?=$(shell go env GOHOSTOS)
GOARCH?=$(shell go env GOARCH)

.PHONY: all
all: iclm_service iclm_edge

.PHONY: clean
clean:
rm iclm_service iclm_edge

iclm_service: service/*.go
CGO_ENABLED=0 GOOS=$(GOHOSTOS) GOARCH=$(GOARCH) \
go build -trimpath -ldflags "-s -w" -o iclm_service service/*.go

iclm_edge: edge/*.go
CGO_ENABLED=0 GOOS=$(GOHOSTOS) GOARCH=$(GOARCH) \
go build -trimpath -ldflags "-s -w" -o iclm_edge edge/*.go
2 changes: 2 additions & 0 deletions examples/iclm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

## Iteractive command-line messaging
Loading