GithubHelp home page GithubHelp logo

micro's Introduction

micro

golang简单实现grpc微服务,部分代码借鉴于go-micro

项目包管理基于go mod管理需要配置

GO111MODULE=on

运行项目

go run main.go

demo

package main

import (
	s "github.com/galen-hlh/micro-sdk/go/idProduce"
	"google.golang.org/grpc/reflection"
	"log"
	"micro/gateway"
	"micro/gateway/registry"
	"micro/modules/idProduce"
)

func main() {
        //设置etcd集群
	etcdRegistry := registry.NewRegistry(func(options *registry.Options) {
		options.Addrs = []string{"127.0.0.1:2379"}
	})
	service := gateway.NewService(
		gateway.Name("idProduce"),            //设置微服务名称
		gateway.Address("127.0.0.1:9501"),    //设置对外暴露端口
		gateway.Registry(etcdRegistry),       //设置服务使用etcd注册
	)

	//初始化服务
	service.Init()

	//服务注册
	s.RegisterIdProduceServer(service.Server().GetGrpcServer(), &idProduce.HelperServer{})
	reflection.Register(service.Server().GetGrpcServer())

	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}

micro's People

Contributors

galen-hlh avatar

Watchers

 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.