Coder Social home page Coder Social logo

micro's Introduction

micro

Go Micro 应用服务化治理实践

github.com/micro/micro

模块创建

micro new --type srv --alias account github.com/hb-go/micro/account/srv
micro new --type api --alias account github.com/hb-go/micro/account/api
micro new --type web --alias account github.com/hb-go/micro/account/web

Protobuf GRPC Gateway

go get github.com/micro/protobuf/{proto,protoc-gen-go}
protoc --go_out=plugins=micro:. account/srv/proto/example/example.proto

# api中import "github.com/micro/go-api/proto/api.proto";
# 报错:github.com/micro/go-api/proto/api.proto: File not found.
# 需要增加依赖的路径 -I$GOPATH/src \
protoc -I/usr/local/include -I. \
  -I$GOPATH/src \
  --go_out=plugins=micro:. \
  post/api/proto/example/example.proto

服务发现-Consul

consul agent -dev -advertise 127.0.0.1

Running

# Post API
go run post/srv/main.go
go run post/api/main.go
micro api
http://localhost:8080/post/post/post?id=1

# Post Web
go run post/web/main.go
micro web
http://localhost:8082/post

API

micro api
micro --enable_stats api
	http://localhost:8080/stats
micro api --namespace=com.example.api

	Make a HTTP call
	curl "http://localhost:8080/greeter/say/hello?name=Asim+Aslam"

	Make an RPC call via the /rpc
	curl -d 'service=go.micro.srv.greeter' \
		-d 'method=Say.Hello' \
		-d 'request={"name": "Asim Aslam"}' \
		http://localhost:8080/rpc

	Make an RPC call via /rpc with content-type set to json
	$ curl -H 'Content-Type: application/json' \
		-d '{"service": "go.micro.srv.greeter", "method": "Say.Hello", "request": {"name": "Asim Aslam"}}' \
		http://localhost:8080/rpc

Web

micro --enable_stats web

micro's People

Contributors

hb-chen avatar

Watchers

 avatar  avatar

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.