Introduce the best practice experience of Go project with a complete project example

通过一个完整的项目的示例,从项目的结构、分层思想、依赖注入、错误处理、单元测试、服务治理、框架选择等方面介绍Go语言项目的最佳实践经验. 项目分为products、details、ratings、reviews四个微服务,依赖关系如下.

dependency

准备

安装docker,go,jsonnet

快速开始

下载项目

    git clone https://github.com/sdgmf/go-project-sample.git
    cd go-project-sample
    git submodule init
    git submodule update
    make docker-compose

截图

Grafana Dashboard,可以自动生成!

dashboard

dashboard1

Prometheus Alert 监控告警,自动生成!

alert

alert

调用链跟踪

jaeger

jaeger

中文文档

Similar Resources

Okta Golang Gin & Okta-Hosted Login Page Example

Okta Golang Gin & Okta-Hosted Login Page Example This example shows you how to use the Okta JWT verifier library to login a user to a Golang Gin appli

Oct 31, 2022

Generate a modern Web project with Go and Angular, React or Vue in seconds 🚀

Generate a modern Web project with Go and Angular, React or Vue in seconds 🚀

Goxygen Generate a Web project with Go and Angular, React or Vue. Goxygen aims at saving your time while setting up a new project. It creates a skelet

Jan 5, 2023

A restful api's with Gin Framework with a structured project that defaults to PostgreSQL database

A restful api's with Gin Framework with a structured project that defaults to PostgreSQL database

Welcome to Golang Gin boilerplate v2 The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to PostgreSQ

Oct 15, 2021

This is a template project to help beginners learn, or to help developers develop some interesting small projects

This is a template project to help beginners learn, or to help developers develop some interesting small projects

This is a template project to help beginners learn, or to help developers develop some interesting small projects

Dec 13, 2022

An open-source project for managing OpenStack resources and OpenStack infrastructure in a Kubernetes cluster

kupenStack Kubernetes-Native OpenStack A Sandbox Project. Have you used OpenStack before? If so, then for you KupenStack is magic ✨ that lets you use

Nov 11, 2021

Project E-Commerce Alta Store Program Immersive Back End Batch 4

Project E-Commerce Alta Store Program Immersive Back End Batch 4

Project E-Commerce Project E-Commerce Alta Store Program Immersive Back End Batch 4 Explore the docs » Daftar Isi About The Project Built With ERD Con

Dec 30, 2021

Kratos Project Template for golang

Kratos Project Template Install Kratos go get -u github.com/go-kratos/kratos/cmd/kratos/v2@latest Create a service # Create a template project kratos

Dec 11, 2021

kubehelper : a golang project patches the replicas field of a kubernetes deployment

kubehelper This golang project patches the replicas field of a kubernetes deployment for scaling purposes, this project is mainly just for fun and lea

Dec 11, 2021

Go gin server project

Go-gin-server-project simple server that is part of the project in "Topics in Pr

Dec 24, 2021
Comments
  • 无法运行项目

    无法运行项目

    $ make docker-compose for app in 'products' 'details' 'ratings' 'reviews' ;
    do
    GOOS=linux GOARCH="amd64" go build -o dist/$app-linux-amd64 ./cmd/$app/;
    GOOS=darwin GOARCH="amd64" go build -o dist/$app-darwin-amd64 ./cmd/$app/;
    done for app in 'products' 'details' 'ratings' 'reviews' ;
    do
    jsonnet -J ./grafana/grafonnet-lib -o ./scripts/grafana/dashboards/$app.json --ext-str app=$app ./scripts/grafana/dashboard.jsonnet ;
    done RUNTIME ERROR: couldn't open import "grafonnet/grafana.libsonnet": no match locally or in the Jsonnet library paths. ./scripts/grafana/dashboard.jsonnet:1:17-53 thunk ./scripts/grafana/dashboard.jsonnet:2:19-26 thunk ./scripts/grafana/dashboard.jsonnet:238:1-10 RUNTIME ERROR: couldn't open import "grafonnet/grafana.libsonnet": no match locally or in the Jsonnet library paths. ./scripts/grafana/dashboard.jsonnet:1:17-53 thunk ./scripts/grafana/dashboard.jsonnet:2:19-26 thunk ./scripts/grafana/dashboard.jsonnet:238:1-10 RUNTIME ERROR: couldn't open import "grafonnet/grafana.libsonnet": no match locally or in the Jsonnet library paths. ./scripts/grafana/dashboard.jsonnet:1:17-53 thunk ./scripts/grafana/dashboard.jsonnet:2:19-26 thunk ./scripts/grafana/dashboard.jsonnet:238:1-10 RUNTIME ERROR: couldn't open import "grafonnet/grafana.libsonnet": no match locally or in the Jsonnet library paths. ./scripts/grafana/dashboard.jsonnet:1:17-53 thunk ./scripts/grafana/dashboard.jsonnet:2:19-26 thunk ./scripts/grafana/dashboard.jsonnet:238:1-10 make: *** [dash] Error 1

    不知是哪里不对?

  • make docker-compose报错

    make docker-compose报错

    克隆下项目后,直接cd go-project-sample/下运行make docker-compose,发生报错: couldn't open import "grafonnet-lib/grafonnet/grafana.libsonnet": no match locally or in the Jsonnet library paths

    发现下面这个路径下是空的: go-project-sample/scripts/grafana/grafonnet-lib/

    建议把https://github.com/grafana/grafonnet-lib/tree/master/grafonnet文件夹直接copy进去,能正常运行。

  • codahale/hdrhistogram repo url has been transferred under the github HdrHstogram umbrella

    codahale/hdrhistogram repo url has been transferred under the github HdrHstogram umbrella

    Problem

    The codahale/hdrhistogram repo has been transferred under the github HdrHstogram umbrella with the help from the original author in Sept 2020 (new repo url https://github.com/HdrHistogram/hdrhistogram-go). The main reasons are to group all implementations under the same roof and to provide more active contribution from the community as the original repository was archived several years ago.

    The dependency URL should be modified to point to the new repository URL. The tag "v0.9.0" was applied at the point of transfer and will reflect the exact code that was frozen in the original repository.

    If you are using Go modules, you can update to the exact point of transfer using the @v0.9.0 tag in your go get command.

    go mod edit -replace github.com/codahale/hdrhistogram=github.com/HdrHistogram/[email protected]
    

    Performance Improvements

    From the point of transfer, up until now (mon 16 aug 2021), we've released 3 versions that aim support the standard HdrHistogram serialization/exposition formats, and deeply improve READ performance. We recommend to update to the latest version.

  • 老板,启动有点问题

    老板,启动有点问题

    老板,我是ubuntu18.04。编译都成功了,就http://localhost:8080/product/1不能访问

    我用docker-compose up 发现如下问题: level=warn ts=2020-11-09T07:26:57.142Z caller=notify.go:674 component=dispatcher receiver=email integration=email[0] msg="Notify attempt failed, will retry later" attempts=1 err="establish connection to server: dial tcp: address tcp/port: unknown port" level=error ts=2020-11-09T07:27:17.143Z caller=dispatch.go:309 component=dispatcher msg="Notify for alerts failed" num_alerts=4 err="email/email[0]: notify retry canceled after 7 attempts: establish connection to server: dial tcp: address tcp/port: unknown port" 这两个找不到端口

Go-todo-api - An example API project written Go and Fiber Framework

This is an example API project written Go and Fiber Framework. Test codes has been written for all controller functions. Environment variables are taken from config.yml.

Jan 24, 2022
Example golang using gin framework everything you need, i create this tutorial special for beginner.

Golang Gin Framework Fundamental Example golang using gin framework everything you need, i create this tutorial special for beginner. Feature Containe

Dec 16, 2022
This application is used as an example HTTP/SQLite application for Litestream tutorials.

This application is used as an example HTTP/SQLite application for Litestream tutorials. It simply maintains a count of HTTP requests and persists it to a SQLite database.

Apr 2, 2022
Example patterns for distributed service

Cloud Native Tulisan ini akan mengulas hasil pembelajaran dari beberapa sumber #learn-from-books. Dan terinspirasi dari obrolan The Pursuit of Product

Jan 30, 2022
A web application example to work with a customer object

Wallester Task This repository contains a web application example to work with a customer object. Build in GO version 1.17.1 Live running app example

Oct 25, 2021
Restful API example with using go and gin framework

simple device api Simple Device API is really simple and concise to show how easy to implement a Restful Service with using Golang. It uses gin framew

Nov 18, 2021
A basic example of a go web server with a react frontend
A basic example of a go web server with a react frontend

GO-React starter This is a basic example of a go web server with a react frontend. It uses the go fiber framework Getting started Running locally Clon

Nov 16, 2021
Advent of Code 2021 example implementation

Advent of Code 2021 example implementation Structure assets/puzzles/<day>.txt contains the puzzle inputs. cmd/<day>/main.go contains the source code d

Dec 15, 2021
A little example about protobuf and Golang

Protocol buffers A little example about protobuf and Golang What is it? - IDL = interface description language - Multilenguage - Optimized serializati

Dec 15, 2021
A simple example application on how a telemetry client can be written

Telemetry Client This is a simple example application on how a telemetry client can be written. Building This application requires that the Go compile

Dec 8, 2021