Spring Cloud golang混合架构的一些优化

EasyNetCN · · 1511 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

因为本身是从java转到golang的,而且团队一直使用Spring Cloud,在实际项目中,golang开发的服务是要保持和Spring Cloud一致,并且架构尽可能做到和Spring Cloud兼容,所以下面观点仅供参考

repository(数据层)要用代码生成器生成,减少人为维护工作,减少错误

repository是基于xorm的(https://gitea.com/xorm/xorm)是自己基于Spring Boot写了一个代码生成器,支持生成entity,基础crud repository,model和把java中的model转换成golang struct

repository的方法命名兼容Spring JPA(https://docs.spring.io/spring-data/jpa/docs/2.4.2

mvc架构使用的是iris(https://github.com/kataras/iris),配置文件没有使用iris的本身配置,而是直接兼容Spring Cloud的bootstrap.yml

spring:
  application:
    name: stats-report-service
    
  profiles:
    active: development-local
  cloud:
    consul:
      host: localhost
      port: 8500
      discovery: 
        ip-address: 
      config:
        prefix: ydyun360-config
  datasource:
    url: ""
    maxIdleConns: 10
    maxOpenConns: 10
    connMaxLifetime: 1800000
  redis:
    host: localhost
    port: 6379
    password:

date-format: 2006-01-02
date-time-format: 2006-01-02 15:04:05
time-zone: Asia/Shanghai 
 
server:
  port: 8023

约定了一些简单规则,比如:

repository r
service s
controller c
数据结构体 entity
服务结构体 m
初始化slice的时候,假如已知长度,可以直接make([]type,len),假如知道最大长度,可以直接make([]type,0,len)

使用golang容器静态编译,基于Dockerfile发布


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:EasyNetCN

查看原文:Spring Cloud golang混合架构的一些优化

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1511 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传