百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

golang-example-app

> 后端框架
开源

示例应用

187 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

示例应用

Golang Example Application

Table of Contents

  • Overview
  • Package list
  • Installing
    • Local environment
    • Docker environment
  • Run services
    • Start in local
    • Start in docker
  • Getting started
    • Jaeger
    • Http with gRPC
    • Graphql with gRPC
  • Deprecate version
  • Testing

Overview

This is an example golang application. Commands list:

  1. Daemon - main service
  2. Product service - service that returns Product, an example of gRPC client/server interaction
  3. Health check service - this service is needed to show how convenient to understand on which of the services an error occurred in jaeger
  4. Migrate - commands for migration
  5. JWT - commands for generate JWT token

Package list

Packages which use in this example project

  1. sql-migrate - SQL migrations
  2. wire - dependency Injection
  3. viper - environment configuration
  4. cobra - create commands
  5. cast - easy casting from one type to another
  6. gorm - database ORM
  7. zap - logger
  8. mux - http router
  9. nats-streaming - NATS Streaming System
  10. gqlgen - graphql server library
  11. protobuf - Google's data interchange format
  12. grpc - RPC framework
  13. opentelemetry - OpenTelemetry
  14. jaeger - Jaeger Bindings for Go OpenTelemetry API
  15. casbin - Supports access control
  16. dataloaden - DataLoader for graphql
  17. nats - Golang client for NATS, the cloud native messaging system

Installing

Install the Golang and GO environment

https://golang.org/doc/install

Install Postgresql (if you want to run locally)

Clone repository

bash
git clone [email protected]:Aristat/golang-example-app.git (go get)

Local environment

Install Golang packages without modules

make install

Install database

make createdb

Sql migrations

sql-migrate up

Install Golang dependencies

make dependencies

Generate artifacts(binary files and configs)

make build

Packages for proto generator

https://grpc.io/docs/languages/go/quickstart/#prerequisites

Set APP_WD if you start to use html templates or path to ssh keys or run make test

bash
export APP_WD=go_path to project_path/resources or project_path/artifacts

Docker environment

Generate docker image

DOCKER_IMAGE=golang-example-app TAG=development make docker-image

Run services

Start in local machine

Up jaeger in docker-compose or disable Jaeger(and rebuild binary file) in resources/configs/*.yaml

docker-compose up jaeger

Start daemon (main service)

make start

or

./artifacts/bin daemon -c ./artifacts/configs/development.yaml -d

Start product service

./artifacts/bin product-service -c ./artifacts/configs/development.yaml -d

Start health-check service

./artifacts/bin health-check -c ./artifacts/configs/development.yaml -d

Start in docker

Run this commands

docker-compose rm # Remove previous containers
REMOVE_CONTAINERS=on DOCKER_IMAGE=golang-example-app TAG=development make docker-image # Generate new docker image
docker-compose up

or run script

./scripts/docker-compose-start.sh

Getting Started

Jaeger

http://localhost:16686

Http example with gRPC

http://localhost:9096/products_grpc

Http example with Nats Streaming

http://localhost:9096/products_nats

Http example with graceful shutdown(long request, you can check the server shutdown)

http://localhost:9096/products_slowly

Graphql example with gRPC

Graphql client for testing. End-point http://localhost:9096/query.

Generate JWT for Graphql authorization

./artifacts/bin jwt token --key='./artifacts/keys/local/private_key.pem' --fields='{"sub": "owner", "iss": "test-service"}'

Set JWT token in headers

{
  "Authorization": "bearer token"
}

Example query

query oneUser {
  users {
    one(email: "[email protected]") {
      email
      id
    }
  }
}

Example query with data loader

query allProducts {
  products {
    list {
      products {
        id
        productItems {
          id
          name
        }
      }
    }
  }
}

Example mutation

mutation createUser {
  users {
    createUser(email: "[email protected]", password: "123456789") {
      id
      email
    }
  }
}

Testing

➜  make test

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gocasbincirclecicobradataloader

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架