github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/docs/v2/framework/micro-service.md (about) 1 --- 2 title: Micro Service 3 keywords: micro, service 4 tags: [micro, service] 5 sidebar: home_sidebar 6 permalink: /micro-service 7 summary: Turn anything into a micro service 8 --- 9 10 Turn anything into a micro service. Micro provides a way of encapsulating anything to become a service. 11 12 ## Overview 13 14 Micro is a runtime which manages microservices. The command line `micro service` encapsulates any app or service 15 making it accessible within the micro ecosystem. The below example is for a basic http app. 16 17 ## HTTP App 18 19 Here's a simple http hello world app 20 21 ``` 22 package main 23 24 import ( 25 "net/http" 26 ) 27 28 func main() { 29 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 30 w.Write([]byte(`hello world`)) 31 }) 32 http.ListenAndServe(":9090", nil) 33 } 34 ``` 35 36 37 Start the service using micro 38 39 ``` 40 micro service --name helloworld --endpoint http://localhost:9090 go run main.go 41 ``` 42 43 Query the service via the cli 44 45 ``` 46 micro call -o raw helloworld / 47 ``` 48 49 ## File Server 50 51 Serve a file back to the caller 52 53 The file /tmp/helloworld.txt 54 55 ``` 56 helloworld 57 ``` 58 59 Run the service 60 61 ``` 62 micro service --name helloworld --endpoint file:///tmp/helloworld.txt 63 ``` 64 65 Get the file 66 67 ``` 68 micro call -o raw helloworld . 69 ``` 70 71 ## Exec script 72 73 Execute a script or command remotely 74 75 ``` 76 #!bin/bash 77 78 echo `date` hello world 79 ``` 80 81 ``` 82 micro service --name helloworld --endpoint exec:///tmp/hellworld.sh 83 ``` 84 85 ``` 86 micro call -o raw helloworld . 87 ``` 88