Micro Service

Turn anything into a micro service

Turn anything into a micro service. Micro provides a way of encapsulating anything to become a service.

Overview

Micro is a runtime which manages microservices. The command line micro service encapsulates any app or service making it accessible within the micro ecosystem. The below example is for a basic http app.

HTTP App

Here’s a simple http hello world app

  1. package main
  2. import (
  3. "net/http"
  4. )
  5. func main() {
  6. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  7. w.Write([]byte(`hello world`))
  8. })
  9. http.ListenAndServe(":9090", nil)
  10. }

Start the service using micro

  1. micro service --name helloworld --endpoint http://localhost:9090 go run main.go

Query the service via the cli

  1. micro call -o raw helloworld /

File Server

Serve a file back to the caller

The file /tmp/helloworld.txt

  1. helloworld

Run the service

  1. micro service --name helloworld --endpoint file:///tmp/helloworld.txt

Get the file

  1. micro call -o raw helloworld .

Exec script

Execute a script or command remotely

  1. #!bin/bash
  2. echo `date` hello world
  1. micro service --name helloworld --endpoint exec:///tmp/hellworld.sh
  1. micro call -o raw helloworld .