package
3.10.13
Repository: https://github.com/micro-community/micro.git
Documentation: pkg.go.dev

# README

Micro API Client godoc

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

Usage

package main

import (
    "fmt"
    "os"

    "github.com/micro-community/micro/v3/client/api"
)

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

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

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

func main() {
 c := api.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

package main

import (
 "fmt"

 "github.com/micro-community/micro/v3/client/api"
)

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

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

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

func main() {
 c := api.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)
 }
}

# Functions

NewClient returns a generic micro client that connects to live by default.

# Constants

Address for api.

# Structs

Client enables generic calls to micro.
Options of the Client.
Request is the request of the generic `api-client` call.
Response is the response of the generic `api-client` call.
No description provided by the author