Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 18 03:03

    pentateu on v0.3.2

    (compare)

  • Apr 18 03:00

    pentateu on v0.3.1

    (compare)

  • Apr 18 02:44

    pentateu on 0.3.1

    (compare)

  • Apr 18 02:42

    pentateu on develop

    Merge pull request #91 from mol… Merge commit 'ea742a76c707b0da9… fix payload for map keys with "… and 1 more (compare)

  • Apr 18 02:40

    pentateu on payload_key_with_dots

    fix payload for map keys with "… (compare)

  • Apr 18 02:11

    pentateu on master

    chore updated readme chore fixed go.mod chore trying to fix drone build and 7 more (compare)

  • Nov 18 2021 08:22
    slaterx review_requested #94
  • Nov 18 2021 08:22
    slaterx commented #94
  • Nov 18 2021 08:04

    slaterx on go_modules

    (compare)

  • Nov 18 2021 08:04

    slaterx on develop

    Bump github.com/tidwall/gjson f… Switching to docker for reenabl… Added kafka service to drone and 5 more (compare)

  • Nov 18 2021 08:04
    slaterx closed #95
  • Nov 18 2021 08:02
    codecov[bot] commented #95
  • Nov 18 2021 08:01
    slaterx synchronize #95
  • Nov 18 2021 08:01

    slaterx on go_modules

    Update .drone.yml (compare)

  • Nov 18 2021 07:41
    slaterx synchronize #95
  • Nov 18 2021 07:41

    slaterx on go_modules

    Update .drone.yml (compare)

  • Nov 18 2021 07:40
    slaterx synchronize #95
  • Nov 18 2021 07:40

    slaterx on go_modules

    Update .drone.yml (compare)

  • Nov 18 2021 07:39
    slaterx synchronize #95
  • Nov 18 2021 07:39

    slaterx on go_modules

    Adding wait for kafka command (compare)

Johnlery
@jtinio
Hi is there a way to return the payload into application/json?
Rafael Almeida
@pentateu
yes.. you ca use an http gateway for that.. have a look here for an example:
This example exposes the actions using http, and also events using websockets..
on line 29
contacts = await postRequest("/api/contacts/find", {
query: { deviceToken }
});
Rafael Almeida
@pentateu
the find action comes from the store.Mixin .. see line 26
back to the UI code.. on line 252:
const result = await postRequest("/api/chat/sendMessage", {
contactId: contact.id,
deviceToken,
message,
target,
individual
});
see that this action.. returns a simple map
return map[string]interface{}{
"result": "message sent",
}
which to the web front end .. the response will be an application/json -> {result:"message sent"}
so.... const result = {result:"message sent"}
Rafael Almeida
@pentateu
that answer your question?let me know if u have issues trying to run the whatsapp app example.
Johnlery
@jtinio
Hi Rafael, Thank you for your quick response

package main

import (
"fmt"

"github.com/moleculer-go/gateway"
"github.com/moleculer-go/moleculer"
"github.com/moleculer-go/moleculer/broker"
"github.com/moleculer-go/moleculer/cli"
"github.com/spf13/cobra"

)

type JS struct {
A int json:"awfnieanifnei"
B int json:"wwdfwf"
}

type IMathService interface {
Name() string
Add(params moleculer.Payload) JS
Sub(a int, b int) int
Inc(a int)
}

type MathService struct {
}

func (s *MathService) Name() string {
return "math"
}

func (s MathService) Add(ctx moleculer.Context, params moleculer.Payload) JS {
ctx.Meta.http.resp.
av := params.Get("a").Int()
bv := params.Get("b").Int()
return JS{A: av, B: bv}
}
func (s
MathService) Sub(a int, b int) int {
return a - b
}

// ⭐ You can also have an action that receive no parameters ⭐
func (s *MathService) Inc(a int) {
//do magic!
fmt.Println("action passed! ", a)
}

func main() {

mathSvc := &MathService{}
gatewaySvc := &gateway.HttpService{
    Settings: map[string]interface{}{"port": "9015"},
}

cli.Start(
    &moleculer.Config{LogLevel: "info"},
    func(broker *broker.ServiceBroker, cmd *cobra.Command) {
        broker.Publish(gatewaySvc, mathSvc)
        broker.Start()
    })

}

Here's my test code
image.png
image.png
Here;'s the postman test
and I was successfully get the json data but it's not application/json
image.png
It's a text/plain
Rafael Almeida
@pentateu
yeah.., that was a bug :) .. I have just pushed the fix to the gateway.. in your go modules make sure you have:
v0.0.1 has the fix ..
also.. you don't need to create this JS struct.. with anotations.. your action just need to return a map[string]interface{} .. and moleculer will serialize in JSON..
no problem doing. the way u did.. it is just that with maps.. or simple objects is more simple.. and moleculer goal.. is to make development simple and flexible.
I also updated the README of this example.. on how to run it :)
Johnlery
@jtinio
Awesome! Thank you for your help! I'll make sure to checkout that whatapp app example that you created. Cheers!
casskir
@casskir
Hi Rafael, Can you check this PR moleculer-go/goemitter#2 ? Some problems with locks =)
Gleidson Nascimento
@slaterx
thanks for the PR @casskir, we will check it and comment on it
just odd that I can’t see the CI info on the PR…
casskir
@casskir
CI not configured for this project
Gleidson Nascimento
@slaterx
oh, okay
let me retry one of the failing jobs, then
Actually, we need to accept the PR first before we can retest the failed jobs...
let’s wait for @pentateu’s feedback :)
casskir
@casskir
Failed tests not fixed yet. I still work on it =)