GithubHelp home page GithubHelp logo

services's Introduction

Micro

Go Report Card Go.Dev reference Apache License

Micro is a Go service development platform. It addresses the core requirements for building services in the cloud by providing a set of APIs which act as the building blocks of any platform. Micro deals with the complexity of distributed systems and provides simpler programmable abstractions for developers to build on.

Overview

Architecture

Below are the core components that make up Micro

Server

Micro is built as a microkernel architecture. It abstracts away the complexity of the underlying infrastructure by providing a set of building block services composed as a single logical server for the end user to consume via an api, cli or sdks.

API

The server embeds a HTTP API (on port 8080) which can be used to make requests as simple JSON. The API automatically maps HTTP Paths and POST requests to internal RPC service names and endpoints.

Proxy

Additionally there's a gRPC proxy (on port 8081) which used to make requests via the CLI or externally. The proxy is identity aware which means it can be used to gatekeep remote access to Micro running anywhere.

Go SDK

Micro comes with a built in Go framework for service based development. The framework lets you write services without piecing together endless lines of boilerplate code. Configured and initialised by default, import it and get started.

CLI

The command line interface includes dynamic command mapping for all services running on the platform. It turns any service instantly into a CLI command along with flag parsing for inputs. Includes support for environments, namespaces, creating and running services, status info and logs.

Environments

Micro bakes in the concept of Environments. Run your server locally for development and in the cloud for production, seamlessly switch between them using the CLI command micro env set [environment].

Install

From Source

make build

Prebuilt Binaries

Windows

powershell -Command "iwr -useb https://raw.githubusercontent.com/micro/micro/master/scripts/install.ps1 | iex"

Linux

wget -q  https://raw.githubusercontent.com/micro/micro/master/scripts/install.sh -O - | /bin/bash

MacOS

curl -fsSL https://raw.githubusercontent.com/micro/micro/master/scripts/install.sh | /bin/bash

Run the server

The server starts with a single command ready to use

micro server

Now go to localhost:8080 and make sure the output is something like {"version": "v3.10.1"}.

Usage

Set the environment e.g local

micro env set local

Login to Micro

Default username/password: admin/micro

$ micro login
Enter username: admin
Enter password:
Successfully logged in.

See what's running:

$ micro services
auth
broker
config
events
network
registry
runtime
store

Create a Service

Generate a service using the template

micro new helloworld

Output

Creating service helloworld

.
├── main.go
├── handler
│   └── helloworld.go
├── proto
│   └── helloworld.proto
├── Makefile
├── README.md
├── .gitignore
└── go.mod


download protoc zip packages (protoc-$VERSION-$PLATFORM.zip) and install:

visit https://github.com/protocolbuffers/protobuf/releases

compile the proto file helloworld.proto:

cd helloworld
make init
go mod vendor
make proto

Edit the code

Edit the protobuf definition in proto/helloworld.proto and run make proto to recompile

Go to handler/helloworld.go to make changes to the response handler

type Helloworld struct{}

func New() *Helloworld {
        return &Helloworld{}
}

func (h *Helloworld) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
        rsp.Msg = "Hello " + req.Name
        return nil
}

Run the service

Run from local dir

micro run .

Or from a git url

micro run github.com/micro/services/helloworld

Check service status

$ micro status
NAME		VERSION	SOURCE					STATUS	BUILD	UPDATED	METADATA
helloworld	latest	github.com/micro/services/helloworld	running	n/a	4s ago	owner=admin, group=micro

View service logs

$ micro logs helloworld
2020-10-06 17:52:21  file=service/service.go:195 level=info Starting [service] helloworld
2020-10-06 17:52:21  file=grpc/grpc.go:902 level=info Server [grpc] Listening on [::]:33975
2020-10-06 17:52:21  file=grpc/grpc.go:732 level=info Registry [service] Registering node: helloworld-67627b23-3336-4b92-a032-09d8d13ecf95

Call via CLI

$ micro helloworld call --name=Jane
{
	"msg": "Hello Jane"
}

Call via API

curl "http://localhost:8080/helloworld/Call?name=John"

Call via SDK

A proto SDK client is used within a service and must be run by micro

package main

import (
	"context"
	"fmt"
	"time"

	"micro.dev/v4/service"
	pb "github.com/micro/services/helloworld/proto"
)

func callService(hw pb.HelloworldService) {
	for {
		// call an endpoint on the service
		rsp, err := hw.Call(context.Background(), &pb.CallRequest{
			Name: "John",
		})
		if err != nil {
			fmt.Println("Error calling helloworld: ", err)
			return
		}

		// print the response
		fmt.Println("Response: ", rsp.Message)

		time.Sleep(time.Second)
	}
}

func main() {
	// create and initialise a new service
	srv := service.New(
		service.Name("caller"),
	)

	// new helloworld client
	hw := pb.NewHelloworldService("helloworld", srv.Client())
	
	// run the client caller
	go callService(hw)
	
	// run the service
	service.Run()
}

Run it

micro run .

Call via Go

Get your user token

export TOKEN=`micro user token`

Call helloworld

package main

import (
    "fmt"
    "os"

    "github.com/micro/micro-go"
)

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

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

func main() {
	token := os.Getenv("TOKEN")
	c := micro.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)
}

Run it

go run main.go

Call via JavaScript

const micro = require('micro-js-client');

new micro.Client({ token: process.env.TOKEN })
  .call('helloworld', 'Call', {"name": "Alice"})
  .then((response) => {
    console.log(response);
  });

Learn More

See the getting started guide to learn more.

Cloud Environment

1 click deploy Micro on DigitalOcean

services's People

Contributors

0o001 avatar a0v0 avatar asim avatar ben-toogood avatar crufter avatar cyb3rko avatar domwong avatar geennuar avatar h1z3y3 avatar joulesdotdev avatar lambdar avatar timmeinerzhagen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

services's Issues

Place API

Create a place API powered by google places. This would allow you to search for places based on location, nearby and do useful things like autocomplete in a UI.

Redis API

You get your own redis cache instance! (with a memory limit)

Ping API

You give a url of the website and micro pings it. (to see if the site is online)

Meme API

Bringing memes to the Micro platform

App API

Provide a simple container API for running containers. Doesn't have to be on our own infra. Can be google cloud run.

Reminder API

An API to provide scheduled reminders. Simple text based reminders to start. Eventually when in promixity to something (location based)

Answer API: example question gives different response now

I tried calling the answer service for questions with the query "google" as shown in the example in this repo services/answer/examples.json.

It does not seem to produce the shown response for the query anymore, instead giving the message Don't have an answer for that but here's a related topic: and then appending the same google description text as before. See below for the real response.

{
  "answer": "Don't have an answer for that but here's a related topic: Google An American multinational technology company that specializes in Internet-related services...",
  "url": "https://duckduckgo.com/Google",
  "image": "https://duckduckgo.com/i/8f85c93f.png"
}

Seems like duckduckgo changed something about this specific keyword, since other companies like microsoft work exactly as described. Might make sense to switch to another example keyword, since this one is not applicable anymore.

Cron API

Cron API which lets things be executed on a schedule and calls an endpoint

Metrics (analytics) API

Provide a simple metrics/analytics API that lets you track counters and related things to do analytics.

Charity API

Donate to charity with endpoints 1/5/10/20 which equate to dollars donated.

Use a predefined charity API to build on.

Todo: replace sendgrid-go with Email Service in User service

User service uses package github.com/sendgrid/sendgrid-go to send email.
But there is Email Service which can replace sendgrid-go;

func (domain *Domain) SendEmail(fromName, toAddress, toUsername, subject, textContent, token, redirctUrl, failureRedirectUrl string) error {
if domain.sengridKey == "" {
return fmt.Errorf("empty email api key")
}
from := mail.NewEmail(fromName, domain.fromEmail)
to := mail.NewEmail(toUsername, toAddress)
// set the text content
textContent = strings.Replace(textContent, "$micro_verification_link", "https://user.m3o.com?token="+token+"&redirectUrl="+url.QueryEscape(redirctUrl)+"&failureRedirectUrl="+url.QueryEscape(failureRedirectUrl), -1)
message := mail.NewSingleEmail(from, subject, to, textContent, "")
// send the email
client := sendgrid.NewSendClient(domain.sengridKey)
response, err := client.Send(message)
logger.Info(response)
return err
}

Space API

Create a space API that provides object storage and potentially CDN URLs for data

Basically blob storage.

DB read limit / offset / order

Add limit / offset and order to the DB Read method. Set max limit to 1000 and return an error if the user specifies over it. Set default limit to 25 if no limit is specified.

test/pubsub is not receiving any messages!

Followed the readme https://github.com/micro/services/tree/master/test/pubsub and got output:

micro logs pubsub
2021-02-04 02:37:58  file=service/service.go:195 level=info Starting [service] pubsub
2021-02-04 02:37:58  file=grpc/grpc.go:939 level=info Server [grpc] Listening on [::]:46639
2021-02-04 02:37:58  file=grpc/grpc.go:956 level=info Broker [service] Connected to :8003
2021-02-04 02:37:58  file=grpc/grpc.go:769 level=info Registry [service] Registering node: pubsub-34d386f6-2871-4a80-a380-66406da9e353
2021-02-04 02:37:58  file=grpc/grpc.go:798 level=info Subscribing to topic: messages

micro version v3.0.4

TODO: Image service

We need an image service with the following endpoints

  • Upload - allocates and returns an s3 bucket where an image can be uploaded/served from
  • Convert - takes an image and converts formats from jpg to png or whatever else
  • Resize - can resize an image to shrink the scale
  • Snapshot - Takes a website url and snapshots a thumbnail

TODO: Add mailing lists to email API

Add the ability to manage mailing lists to the email service.

  • Email.List - List all the emails in a list
  • Email.Subscribe - Subscribe to a list

File service bug

{"Id":"go.micro.client","Code":500,"Detail":"grpc: failed to unmarshal the received message json: cannot unmarshal array into Go value of type map[string]json.RawMessage","Status":"Internal Server Error"

CDN API

CDN api built on s3 serving cdn.m3ocontent.com

Presence API

Required to determine whether someone is present

exec: "go": executable file not found in $PATH

Hello.
I followed https://micro.mu/getting-started#getting-started upto micro run github.com/micro/services/helloworld and got "go": executable file not found in $PATH error message.
~# ls -l which go
-rwxr-xr-x 1 root root 14244478 Dec 3 17:35 /usr/local/go/bin/go
~# micro run github.com/micro/services/helloworld
exec: "go": executable file not found in $PATH
But go apparently is in $PATH. What could be the problem?

Thanks

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.