micro

command module
v3.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

Micro

Go Report Card Go.Dev reference Apache License

An API first development platform

New feature

  • Third Party authentication
  • Support global tracing, request id for api gateway
  • Support web service, proxy from api gateway
  • Support std restful response
  • Support rpc with account
  • Support rotate logs
  • Optimize dashboard
  • Staging/Local model
  • New micro boilerplate

Authentication advice

  • Use third-party api gateway authentication
  • Custom Inspect method in service/auth/server/server.go:46 and use default rule

Overview

Micro addresses the key requirements for building services in the cloud. It leverages the microservices architecture pattern and provides a set of services which act as the building blocks of a platform.

Micro deals with the complexity of distributed systems and provides simpler programmable abstractions to build on.

Features

Below are the core components that make up Micro.

Server

Micro is built as a microservices architecture and abstracts away the complexity of the underlying infrastructure. We compose this as a single logical server to the user but decompose that into the various building block primitives that can be plugged into any underlying system.

The server is composed of the following services.

  • API - A Gateway which dynamically maps HTTP requests to RPC using path based resolution
  • Auth - Authentication and authorization out of the box using JWT tokens and rule based access control.
  • Broker - Ephemeral pubsub messaging for asynchronous communication and distributing notifications
  • Config - Dynamic configuration and secrets management for service level config without reload
  • Events - Event streaming with ordered messaging, replay from offsets and persistent storage
  • Network - Inter-service networking, isolation and routing plane for all internal request traffic
  • Proxy - An identity aware proxy used for remote access and any external grpc request traffic
  • Runtime - Service lifecycle and process management with support for source to running auto build
  • Registry - Centralised service discovery and API endpoint explorer with feature rich metadata
  • Store - Key-Value storage with TTL expiry and persistent crud to keep microservices stateless

Framework

Micro comes with a built in Go framework for service development. The Go framework makes it drop dead simple to write your services without having to piece together endless lines of boilerplate code. Auto configured and initialised by default, just import and get started quickly.

Command Line

Micro brings not only a rich architectural model but a command line experience tailored for that need. The command line interface includes dynamic command mapping for all services running on the platform. Turns any service instantly into a CLI command along with flag parsing for inputs. Includes support for multiple environments and namespaces, automatic refreshing of auth credentials, creating and running services, status info and log streaming, plus much, much more.

Dashboard

Explore, discover and consume services via a browser using Micro Web. The dashboard makes use of your env configuration to locate the server and provides dynamic form fill for services.

Environments

Micro bakes in the concept of Environments and multi-tenancy through Namespaces. Run your server locally for development and in the cloud for staging and production, seamlessly switch between them using the CLI commands micro env set [environment] and micro user set [namespace].

Installation

From Source
go install github.com/2637309949/micro/v3@latest
Install Binaries
Windows
powershell -Command "iwr -useb https://raw.githubusercontent.com/2637309949/micro/master/scripts/install.ps1 | iex"

Linux
wget -q  https://raw.githubusercontent.com/2637309949/micro/master/scripts/install.sh -O - | /bin/bash
MacOS
curl -fsSL https://raw.githubusercontent.com/2637309949/micro/master/scripts/install.sh | /bin/bash
Run the server
micro server

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

Usage

Login to Micro

default username: admin

default password: micro

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

See what's running:

$ micro services
api
auth
broker
config
events
network
proxy
registry
runtime
server
store
Create a Service

Generate a service using the template

micro new helloworld

Output

Creating service helloworld

.
├── micro.mu
├── main.go
├── generate.go
├── handler
│   └── helloworld.go
├── proto
│   └── helloworld.proto
├── Dockerfile
├── 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
Run a service

Run from local dir

micro run .

Or from a git url

micro run github.com/micro/services/helloworld
Check status of running service
$ 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 logs of the service to verify it's running.
$ 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 the service
$ micro helloworld call --name=Jane
{
	"msg": "Hello Jane"
}

Curl it

curl "http://localhost:8080/helloworld?name=John"
Write a service client

A service client is used within another service and must be run by micro

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/2637309949/micro/v3/service"
	"github.com/2637309949/micro/v3/service/client"
	proto "github.com/micro/services/helloworld/proto"
)

func callService(c client.Client) {
	// create the proto client for helloworld
	hw := proto.NewHelloworldService("helloworld", c)

	for {
		// call an endpoint on the service
		rsp, err := hw.Call(context.Background(), &proto.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"),
	)

	// run the client caller
	go callService(srv.Client())
	
	// run the service
	service.Run()
}

Run it

micro run .
Write an api client

An api client is an external app or client which makes requests through the micro api

Get a token

export TOKEN=`micro user token`

Call helloworld

package main

import (
    "fmt"
    "os"

    "github.com/2637309949/micro/v3/client/api"
)

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

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

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

Run it

go run main.go

For more see the getting started guide.

Web Dashboard

Use services via the web with the Micro Web dashboard

micro web

Browse to localhost:8082

Docs

  • Introduction - A high level introduction to Micro
  • Getting Started - The helloworld quickstart guide
  • Upgrade Guide - Update your go-micro project to use micro v3.
  • Architecture - Describes the architecture, design and tradeoffs
  • Reference - In-depth reference for Micro CLI and services
  • Resources - External resources and contributions
  • Roadmap - Stuff on our agenda over the long haul
  • FAQ - Frequently asked questions

License

See LICENSE which makes use of Apache 2.0.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
client
api
Package api provides a micro api client
Package api provides a micro api client
cli
Package cli is a command line interface
Package cli is a command line interface
cli/gen
Package gen provides the micro gen command which simply runs go generate
Package gen provides the micro gen command which simply runs go generate
cli/init
Package init provides the micro init command for initialising plugins and imports
Package init provides the micro init command for initialising plugins and imports
cli/new
Package new generates micro service templates
Package new generates micro service templates
cli/run
Package runtime is the micro runtime
Package runtime is the micro runtime
cli/shutdown
Package shutdown will issue a shutdown signal
Package shutdown will issue a shutdown signal
cli/store
Package cli implements the `micro store` subcommands for example:
Package cli implements the `micro store` subcommands for example:
cli/token
Package token contains CLI client token related helpers tToken files consist of one line per token, each token having the structure of `micro://envAddress/namespace[/id]:token`, ie.
Package token contains CLI client token related helpers tToken files consist of one line per token, each token having the structure of `micro://envAddress/namespace[/id]:token`, ie.
cli/user
Package user handles the user cli command
Package user handles the user cli command
cli/util
Package cliutil contains methods used across all cli commands @todo: get rid of os.Exits and use errors instread
Package cliutil contains methods used across all cli commands @todo: get rid of os.Exits and use errors instread
web
Package web is a web dashboard
Package web is a web dashboard
cmd
protoc-gen-micro
protoc-gen-micro is a plugin for the Google protocol buffer compiler to generate Go code.
protoc-gen-micro is a plugin for the Google protocol buffer compiler to generate Go code.
protoc-gen-micro/generator
The code generator for the plugin for the Google protocol buffer compiler.
The code generator for the plugin for the Google protocol buffer compiler.
server
Package server is the micro server which runs the whole system
Package server is the micro server which runs the whole system
service
Package service provides micro service commands
Package service provides micro service commands
usage
Package usage tracks micro usage
Package usage tracks micro usage
etcd
Package etcd provides an etcd service registry
Package etcd provides an etcd service registry
nats/broker
Package nats provides a NATS broker
Package nats provides a NATS broker
postgres
Package postgres implements the postgres store
Package postgres implements the postgres store
postgres/pgx
Package pgx implements the postgres store with pgx driver
Package pgx implements the postgres store with pgx driver
s3
Package profile is for specific profiles @todo this package is the definition of cruft and should be rewritten in a more elegant way
Package profile is for specific profiles @todo this package is the definition of cruft and should be rewritten in a more elegant way
ci
Package ci is for continuous integration testing
Package ci is for continuous integration testing
platform
Package platform is a profile for running a highly available Micro platform
Package platform is a profile for running a highly available Micro platform
proto
api
api
api/handler
Package handler provides http handlers
Package handler provides http handlers
api/handler/api
Package api provides an http-rpc handler which provides the entire http request over rpc
Package api provides an http-rpc handler which provides the entire http request over rpc
api/handler/event
Package event provides a handler which publishes an event
Package event provides a handler which publishes an event
api/handler/http
Package http is a http reverse proxy handler
Package http is a http reverse proxy handler
api/handler/rpc
Package rpc is a go-micro rpc handler.
Package rpc is a go-micro rpc handler.
api/handler/web
Package web contains the web handler including websocket support
Package web contains the web handler including websocket support
api/resolver
Package resolver resolves a http request to an endpoint
Package resolver resolves a http request to an endpoint
api/resolver/grpc
Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
api/resolver/host
Package host resolves using http host
Package host resolves using http host
api/resolver/path
Package path resolves using http path
Package path resolves using http path
api/resolver/subdomain
Package subdomain is a resolver which uses the subdomain to determine the domain to route to.
Package subdomain is a resolver which uses the subdomain to determine the domain to route to.
api/resolver/vpath
Package vpath resolves using http path and recognised versioned urls
Package vpath resolves using http path and recognised versioned urls
api/router
Package router provides api service routing
Package router provides api service routing
api/router/registry
Package registry provides a dynamic api service router
Package registry provides a dynamic api service router
api/server/http
Package http provides a http server with features; acme, cors, etc
Package http provides a http server with features; acme, cors, etc
auth/jwt
Package jwt is a jwt implementation of the auth interface
Package jwt is a jwt implementation of the auth interface
broker
Package broker is the micro broker
Package broker is the micro broker
broker/memory
Package memory provides a memory broker
Package memory provides a memory broker
build/util/tar
Package tar is a wrapper around archive/tar, it's used for archiving and unarchiving source from and into folders on the host.
Package tar is a wrapper around archive/tar, it's used for archiving and unarchiving source from and into folders on the host.
build/util/zip
Package zip is a wrapper around archive/zip, it's used for archiving and unarchiving source from and into folders on the host.
Package zip is a wrapper around archive/zip, it's used for archiving and unarchiving source from and into folders on the host.
client
Package client is an interface for an RPC client
Package client is an interface for an RPC client
client/grpc
Package grpc provides a gRPC client
Package grpc provides a gRPC client
client/mucp
Package mucp provides a transport agnostic RPC client
Package mucp provides a transport agnostic RPC client
config
Package config is an interface for dynamic configuration.
Package config is an interface for dynamic configuration.
config/env
Package env provides config from environment variables
Package env provides config from environment variables
context
Package context provides a context for accessing services
Package context provides a context for accessing services
context/metadata
Package metadata is a way of defining message headers
Package metadata is a way of defining message headers
debug/handler
Package handler implements service debug handler embedded in go-micro services
Package handler implements service debug handler embedded in go-micro services
debug/log
Package log provides debug logging
Package log provides debug logging
debug/log/kubernetes
Package kubernetes is a logger implementing (github.com/micro/go-micro/v3/debug/log).Log
Package kubernetes is a logger implementing (github.com/micro/go-micro/v3/debug/log).Log
debug/log/memory
Package memory provides an in memory log buffer
Package memory provides an in memory log buffer
debug/profile
Package profile is for profilers
Package profile is for profilers
debug/profile/http
Package http enables the http profiler
Package http enables the http profiler
debug/profile/pprof
Package pprof provides a pprof profiler which writes output to /tmp/[name].{cpu,mem}.pprof
Package pprof provides a pprof profiler which writes output to /tmp/[name].{cpu,mem}.pprof
debug/stats
Package stats provides runtime stats
Package stats provides runtime stats
debug/trace
Package trace provides an interface for distributed tracing
Package trace provides an interface for distributed tracing
errors
Package errors provides a way to return detailed information for an RPC request error.
Package errors provides a way to return detailed information for an RPC request error.
events
Package events is for event streaming and storage
Package events is for event streaming and storage
logger
Package log provides a log interface
Package log provides a log interface
metrics
Package metrics is for instrumentation and debugging
Package metrics is for instrumentation and debugging
model
Package model implements convenience methods for managing indexes on top of the Store.
Package model implements convenience methods for managing indexes on top of the Store.
network
Package network implements micro network node
Package network implements micro network node
network/resolver
Package resolver resolves network names to addresses
Package resolver resolves network names to addresses
network/resolver/dns
Package dns resolves names to dns records
Package dns resolves names to dns records
network/resolver/dnssrv
Package dns srv resolves names to dns srv records
Package dns srv resolves names to dns srv records
network/resolver/http
Package http resolves names to network addresses using a http request
Package http resolves names to network addresses using a http request
network/resolver/noop
Package noop is a noop resolver
Package noop is a noop resolver
network/resolver/registry
Package registry resolves names using the go-micro registry
Package registry resolves names using the go-micro registry
network/resolver/static
Package static is a static resolver
Package static is a static resolver
network/transport
Package transport is an interface for synchronous connection based communication
Package transport is an interface for synchronous connection based communication
network/transport/grpc
Package grpc provides a grpc transport
Package grpc provides a grpc transport
network/transport/memory
Package memory is an in-memory transport
Package memory is an in-memory transport
network/tunnel
Package tunnel provides gre network tunnelling
Package tunnel provides gre network tunnelling
network/tunnel/broker
Package broker is a tunnel broker
Package broker is a tunnel broker
network/tunnel/transport
Package transport provides a tunnel transport
Package transport provides a tunnel transport
proxy
Package proxy is a transparent proxy built on the go-micro/server
Package proxy is a transparent proxy built on the go-micro/server
proxy/grpc
Package grpc is a grpc proxy built for the go-micro/server
Package grpc is a grpc proxy built for the go-micro/server
proxy/http
Package http provides a micro rpc to http proxy
Package http provides a micro rpc to http proxy
proxy/mucp
Package mucp transparently forwards the incoming request using a go-micro client.
Package mucp transparently forwards the incoming request using a go-micro client.
registry
Package registry is the micro registry
Package registry is the micro registry
registry/cache
Package cache provides a registry cache
Package cache provides a registry cache
registry/memory
Package memory provides an in-memory registry
Package memory provides an in-memory registry
registry/noop
Package noop is a registry which does nothing
Package noop is a registry which does nothing
router/kubernetes
Package kubernetes is a kubernetes router which uses the service name and network to route
Package kubernetes is a kubernetes router which uses the service name and network to route
runtime
Package runtime is a service runtime manager
Package runtime is a service runtime manager
runtime/kubernetes
Package kubernetes implements kubernetes micro runtime
Package kubernetes implements kubernetes micro runtime
runtime/kubernetes/client
Package client provides an implementation of a restricted subset of kubernetes API client
Package client provides an implementation of a restricted subset of kubernetes API client
runtime/local/process
Package process executes a binary
Package process executes a binary
runtime/local/process/os
Package os runs processes locally
Package os runs processes locally
runtime/local/test/bar
Package main is used to test the local runtime, specifically the entrypoint function
Package main is used to test the local runtime, specifically the entrypoint function
runtime/local/test/foo/cmd/bar
Package main is used to test the local runtime, specifically the entrypoint function
Package main is used to test the local runtime, specifically the entrypoint function
runtime/local/test/foo/cmd/baz
Package main is used to test the local runtime, specifically the entrypoint function
Package main is used to test the local runtime, specifically the entrypoint function
runtime/local/test/qux/cmd/test
Package main is used to test the local runtime, specifically the entrypoint function
Package main is used to test the local runtime, specifically the entrypoint function
runtime/source
Package source retrieves source code
Package source retrieves source code
runtime/source/go
Package golang is a source for Go
Package golang is a source for Go
server/grpc
Package grpc provides a grpc server
Package grpc provides a grpc server
server/mucp
Package mucp provides a transport agnostic RPC server
Package mucp provides a transport agnostic RPC server
store
Package store is an interface for distributed data storage.
Package store is an interface for distributed data storage.
store/file
Package local is a file system backed store
Package local is a file system backed store
store/memory
Package memory is a in-memory store store
Package memory is a in-memory store store
fakes
Code generated by counterfeiter.
Code generated by counterfeiter.
util
acme
Package acme abstracts away various ACME libraries
Package acme abstracts away various ACME libraries
acme/autocert
Package autocert is the ACME provider from golang.org/x/crypto/acme/autocert This provider does not take any config.
Package autocert is the ACME provider from golang.org/x/crypto/acme/autocert This provider does not take any config.
acme/certmagic
Package certmagic is the ACME provider from github.com/caddyserver/certmagic
Package certmagic is the ACME provider from github.com/caddyserver/certmagic
backoff
Package backoff provides backoff functionality
Package backoff provides backoff functionality
buf
codec
Package codec is an interface for encoding messages
Package codec is an interface for encoding messages
codec/bytes
Package bytes provides a bytes codec which does not encode or decode anything
Package bytes provides a bytes codec which does not encode or decode anything
codec/grpc
Package grpc provides a grpc codec
Package grpc provides a grpc codec
codec/json
Package json provides a json codec
Package json provides a json codec
codec/jsonrpc
Package jsonrpc provides a json-rpc 1.0 codec
Package jsonrpc provides a json-rpc 1.0 codec
codec/proto
Package proto provides a proto codec
Package proto provides a proto codec
codec/protorpc
Protorpc provides a net/rpc proto-rpc codec.
Protorpc provides a net/rpc proto-rpc codec.
codec/text
Package text reads any text/* content-type
Package text reads any text/* content-type
config
Package config contains helper methods for client side config management (`~/.micro/config.json` file).
Package config contains helper methods for client side config management (`~/.micro/config.json` file).
ctx
muxer
Package muxer provides proxy muxing
Package muxer provides proxy muxing
net
pool
Package pool is a connection pool
Package pool is a connection pool
qson
Package qson implmenets decoding of URL query params into JSON and Go values (using JSON struct tags).
Package qson implmenets decoding of URL query params into JSON and Go values (using JSON struct tags).
report
Package report contains CLI error reporting and handling and cleanup methods.
Package report contains CLI error reporting and handling and cleanup methods.
ring
Package ring provides a simple ring buffer for storing local data
Package ring provides a simple ring buffer for storing local data
selector
Package selector is for node selection and load balancing
Package selector is for node selection and load balancing
socket
Package socket provides a pseudo socket
Package socket provides a pseudo socket
sync
Package sync is an interface for distributed synchronization
Package sync is an interface for distributed synchronization
sync/memory
Package memory provides a sync.Mutex implementation of the lock for local use
Package memory provides a sync.Mutex implementation of the lock for local use
tls

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL