Giter VIP home page Giter VIP logo

go-real-world-web-app's Introduction

go-real-world-web-app

Gin + Gorm2 搭建企业级应用

做了一个视频,介绍和演示了这个项目:https://www.bilibili.com/video/BV15P4y147Ce
此示例包含:

  1. 企业级应用的分层架构
  2. gin + 最新版gorm的示例 (gorm2相对于jinzhu包的第一版gorm)
  3. 四个middleware
    1.1 cors
    1.2 authentication
    1.3 log
    1.4 error message
  4. ldap 登录功能
  5. 支持持久存储的postgre sql docker脚本
  6. 基于sqlite的自动化测试
  7. 初始化/客户化脚本

一些关于技术的选择

1. 分层

2. 数据库主键

  • 自增优点:
    • 存储空间小
    • 查询效率高
  • uuid优点:
    • 分布式友好
    • 避免暴露业务规模
  • snowflake

3. 返回值struct vs. pointer

https://www.ardanlabs.com/blog/2014/12/using-pointers-in-go.html

4. 尽量避免在运行时创建实例

5. ldap

apache directory studio的使用: https://www.bilibili.com/video/BV1kh411h7yB?from=search&seid=4698533963557832110

6. 运行在docker中的postgre sql

7. 命名规范

包的名称用单数
https://rakyll.org/style-packages/
golang-standards/project-layout#7

8. 自动化测试

初始化/客户化脚本:

for filename in find . -type f -name 'post*'; do mv -v "$filename" "${filename//post/[replacement]}"; done
find ./ -type f -exec sed -i -e 's/post/[replacement]/g' {} ;
find ./ -type f -exec sed -i -e 's/Post/[Replacement]/g' {} ;
find ./ -type f -exec sed -i -e 's/Methed[Replacement]/MethodPost/g' {} ;
find ./ -type f -exec sed -i -e 's/"blog"/"[replacement]"/g' {} ;
find ./ -type f -exec sed -i -e 's/[replacement]gres/postgres/g' {} ;

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.