Skip to content

GWT-M3O-TEST/m3o-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

M3O Go Client godoc Go Report Card Apache 2.0 License

This is the Go client to access APIs on the M3O Platform

Usage

Call a service using the generated client. Populate the M3O_API_TOKEN environment variable.

Import the package and initialise the service with your API token.

package main

import(
        "fmt"
        "os"

        "go.m3o.com/helloworld"
)

// Call returns a personalised "Hello $name" response
func main() {
        helloworldService := helloworld.NewHelloworldService(os.Getenv("M3O_API_TOKEN"))
        rsp, err := helloworldService.Call(&helloworld.CallRequest{
                Name: "John",

        })
        fmt.Println(rsp, err)
}

Generic Client

The generic client enables you to call any endpoint by name with freeform request/response types.

package main

import (
    "fmt"
    "os"

    "go.m3o.com/client"
)

type Request struct {
	Name string `json:"name"`
}

type Response struct {
	Msg string `json:"msg"`
}

var (
	token, _ = os.Getenv("TOKEN")
)

func main() {
	c := client.NewClient(nil)

	// set your api token
	c.SetToken(token)

   	req := &Request{
		Name: "John",
	}
	
	var rsp Response

	if err := c.Call("helloworld", "call", req, &rsp); err != nil {
		fmt.Println(err)
		return
	}
	
	fmt.Println(rsp)
}

Streaming

The client supports streaming but is not yet code generated. Use the following for streaming endpoints.

package main

import (
	"fmt"

	"go.m3o.com/client"
)

type Request struct {
	Count string `json:"count"`
}

type Response struct {
	Count string `json:"count"`
}

var (
	token, _ = os.Getenv("TOKEN")
)

func main() {
	c := client.NewClient(nil)

	// set your api token
	c.SetToken(token)
	
	stream, err := c.Stream("streams", "subscribe", Request{Count: "10"})
	if err != nil {
		fmt.Println(err)
		return
	}

	for {
		var rsp Response
		if err := stream.Recv(&rsp); err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println("got", rsp.Count)
	}
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages