Giter VIP home page Giter VIP logo

go-kura's Introduction

GoDoc

go-kura

Some utilities to parse Eclipse Kura payloads in Go.

Kura Datatype

The kuradatatypes package contains the protobuf generated Go code for the Kura payload as defined in the Kura repository:

https://github.com/eclipse/kura/blob/develop/kura/org.eclipse.kura.core.cloud/src/main/protobuf/kurapayload.proto

In order to use the kuradatatypes package you can import it in your Go program using:

package main

import (
    pb "github.com/federicobaldo/go-kura/kuradatatypes"
    "github.com/golang/protobuf/jsonpb"
    "fmt"
    )

func main(){

    metric_name := "mymetric"

    metric_type := pb.KuraPayload_KuraMetric_STRING

    metric := &pb.KuraPayload_KuraMetric{
                            Name: &metric_name,
                            Type: &metric_type,
                            }

    metrics := []*pb.KuraPayload_KuraMetric{metric}
							
    message := &pb.KuraPayload{
                        Metric: metrics,
                        }

    fmt.Printf("Here my Kura payload as string: %s\n", message)

    marshaler := &jsonpb.Marshaler{}
    json_string, _ := marshaler.MarshalToString(message)
    
    fmt.Printf("Here my Kura payload as json string: %s\n", json_string)
}

Examples

You can find some example programs in the ./examples folder.

The mqtt_subscriber example, subscribe to an mqtt topic and convert the KuraPayload to a json string. Here the usage:

Usage of examples/mqtt_subscriber:
  -clientid string
    	A clientid for the connection (default "localhost")
  -log.level value
    	Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal, panic]. (default info)
  -password string
    	Password to match username
  -qos int
    	The QoS to subscribe to messages at
  -server string
    	The full url of the MQTT server to connect to ex: tcp://127.0.0.1:1883 (default "tcp://127.0.0.1:1883")
  -topic string
    	Topic to subscribe to (default "#")
  -username string
    	A username to authenticate to the MQTT server

You can build the examples using go build filename.go

Detailed instructions on how to setup your development environment are here: https://golang.org/doc/code.html

go-kura's People

Contributors

federicobaldo avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.