Code Monkey home page Code Monkey logo

oms-demo's Introduction

命名规范

  1. service层声明接口需要以XxxService方式命名,接口实现需要xxxServiceImpl方式命名
  2. repository层声明接口需要以XxxRepository方式命名,接口实现需要xxxRepositoryImpl方式命名
  3. cache层声明接口需要以XxxCache方式命名,接口实现需要xxxCacheImpl方式命名
  4. grpc层声明struct需要以xxxGrpcServer方式命名
  5. http层声明struct需要以xxxHttpServer方式命名

依赖注入

通过配置结构体标签来指定注入哪些对象

type productServiceImpl struct {
	productRepository repository.ProductRepository `autowire:""`
	storeCache        cache.StoreCache             `autowire:""`
	productDb         *gorm.DB                     `autowire:"product-center"`
}

情况1: 根据数据类型来注入,找不到实例注入对象就会报错

type productServiceImpl struct {
	productRepository repository.ProductRepository `autowire:""`
}

情况2: 在多个相同数据类型情况下,根据bean名称来注入,找不到实例注入对象就会报错

type productServiceImpl struct {
	productDb         *gorm.DB                     `autowire:"product-center"`
}

情况3: 容器中存在就注入,不存在就不注入

type productServiceImpl struct {
	storeCache        cache.StoreCache             `autowire:"?"`
}

注册实例

通过gs.Provide()来注册,第一个参数是实例化方法,后面是实例化方法参数 比如:NewProductService("zihua")

func init() {
    gs.Provide(NewProductService,"zihua")
}

通过gs.Object()来注册

func init() {
	gs.Object(new(greeterGrpcServer)).Init(func(s *greeterGrpcServer) {
		gs.GrpcServer("helloworld.Greeter", &grpc.Server{
			Register: helloworld.RegisterGreeterServer,
			Service:  s,
		})
	})
}

proto生成

先安装proto生成工具

https://docs.buf.build/installation

执行生成pb文件

buf generate

oms-demo's People

Watchers

mayb 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.