mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* MF-354 - Add Go SDK This PR adds Go SDK. It also refactors `cli` to use new SDK. Signed-off-by: drasko <drasko.draskovic@gmail.com> * Use http consts. Add doc. Signed-off-by: drasko <drasko.draskovic@gmail.com> * Insline const Signed-off-by: drasko <drasko.draskovic@gmail.com> * Add initial SDK tests Signed-off-by: drasko <drasko.draskovic@gmail.com> * Fix SDK to return values (not HTTP rsp) Signed-off-by: drasko <drasko.draskovic@gmail.com> * Fix CLI and test Signed-off-by: drasko <drasko.draskovic@gmail.com> * fix typos, add header Signed-off-by: drasko <drasko.draskovic@gmail.com> * Fix doc Signed-off-by: drasko <drasko.draskovic@gmail.com> * Fix doc, add comment Signed-off-by: drasko <drasko.draskovic@gmail.com> * Inline error checks Signed-off-by: drasko <drasko.draskovic@gmail.com> * Fix typos Signed-off-by: drasko <drasko.draskovic@gmail.com> * Inline errs Signed-off-by: drasko <drasko.draskovic@gmail.com> * Fix typo Signed-off-by: drasko <drasko.draskovic@gmail.com> * Change fnc parameter name Signed-off-by: drasko <drasko.draskovic@gmail.com> * Rename getters to Go standard Signed-off-by: drasko <drasko.draskovic@gmail.com> * Use struct and interface Signed-off-by: drasko <drasko.draskovic@gmail.com> * Simplify sdk struct Signed-off-by: drasko <drasko.draskovic@gmail.com> * Fix README Signed-off-by: drasko <drasko.draskovic@gmail.com>
48 lines
869 B
Go
48 lines
869 B
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package cli
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const contentTypeSenml = "application/senml+json"
|
|
|
|
var cmdMessages = []cobra.Command{
|
|
cobra.Command{
|
|
Use: "send",
|
|
Short: "send <channel_id> <JSON_string> <thing_token>",
|
|
Long: `Sends message on the channel`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if len(args) != 3 {
|
|
logUsage(cmd.Short)
|
|
return
|
|
}
|
|
if err := sdk.SendMessage(args[0], args[1], args[2]); err != nil {
|
|
logError(err)
|
|
return
|
|
}
|
|
logOK()
|
|
},
|
|
},
|
|
}
|
|
|
|
func NewMessagesCmd() *cobra.Command {
|
|
cmd := cobra.Command{
|
|
Use: "msg",
|
|
Short: "Send or retrieve messages",
|
|
Long: `Send or retrieve messages: control message flow on the channel`,
|
|
}
|
|
|
|
for i := range cmdMessages {
|
|
cmd.AddCommand(&cmdMessages[i])
|
|
}
|
|
|
|
return &cmd
|
|
}
|