Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

YOLO API using Go, Gin, Gorm, Logrus

NotificationsYou must be signed in to change notification settings

tqmvt/yolo-backend

Repository files navigation

Written in Golang with Gin Framework and Gorm

Motivation

Write restful API forYOLO game with fast development and developer friendly

Table of Contents

Configuration Manage

ENV Manage

  • Default ENV Configuration Manage from.env. sample file.env.example
# Server ConfigurationSECRET=h9wt*pasj6796j##w(w8=xaje8tpi6h*r&hzgrz065u&ed+k2)DEBUG=True # `False` in ProductionALLOWED_HOSTS=0.0.0.0SERVER_HOST=0.0.0.0SERVER_PORT=8000# Database ConfigurationMASTER_DB_NAME=test_pg_goMASTER_DB_USER=mamunMASTER_DB_PASSWORD=123MASTER_DB_HOST=postgres_dbMASTER_DB_PORT=5432MASTER_DB_LOG_MODE=True # `False` in ProductionMASTER_SSL_MODE=disableREPLICA_DB_NAME=test_pg_goREPLICA_DB_USER=mamunREPLICA_DB_PASSWORD=123REPLICA_DB_HOST=localhostREPLICA_DB_PORT=5432REPLICA_DB_LOG_MODE=True # `False` in ProductionREPLICA_SSL_MODE=disable
  • ServerDEBUG setFalse in Production
  • Database LoggerMASTER_DB_LOG_MODE andREPLICA_DB_LOG_MODE setFalse in production
  • If ENV Manage from YAML file add a config.yml file and configurationdb.go andserver.go. See MoreENV YAML Configure

Server Configuration

  • UseGin Web Framework

Database Configuration

  • UseGORM as an ORM
  • Use databaseMASTER_DB_HOST value set aslocalhost for local development, and usepostgres_db for docker development

PG Admin

  • Check PG Admin onhttp://0.0.0.0:5050/browser/
  • Login with Credential Emailadmin@admin.com Passwordroot
  • Connect Database Host aspostgres_db, DB Username and Password as per.env set
  • Note: if not configure.env, default Usernamemamun and password123

Installation

Local Setup Instruction

Follow these steps:

  • Copy.env.example as.env and configure necessary values
  • To add all dependencies for a package in your modulego get . in the current directory
  • Locally rungo run main.go orgo build main.go and run./main. or runair to host with hot reloading
  • Check Application health available on0.0.0.0:8000/health

Develop Application in Docker with Live Reload

Follow these steps:

Deployment

Container Development Build

  • Runmake build

Container Production Build and Up

  • Runmake production

ENV Yaml Configure

database:driver:"postgres"dbname:"test_pg_go"username:"mamun"password:"123"host:"postgres_db"# use `localhost` for local developmentport:"5432"ssl_mode:disablelog_mode:falseserver:host:"0.0.0.0"port:"8000"secret:"secret"allow_hosts:"localhost"debug:false#use `false` in productionrequest:timeout:100
funcServerConfig()string {viper.SetDefault("server.host","0.0.0.0")viper.SetDefault("server.port","8000")appServer:=fmt.Sprintf("%s:%s",viper.GetString("server.host"),viper.GetString("server.port"))returnappServer}
funcDbConfiguration()string {dbname:=viper.GetString("database.dbname")username:=viper.GetString("database.username")password:=viper.GetString("database.password")host:=viper.GetString("database.host")port:=viper.GetString("database.port")sslMode:=viper.GetString("database.ssl_mode")dsn:=fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=%s",host,username,password,dbname,port,sslMode)returndsn}

Useful Commands

  • make dev: make dev for development work
  • make build: make build container
  • make production: docker production build and up
  • clean: clean for all clear docker images

Use Packages

  • Viper - Go configuration with fangs.
  • Gorm - The fantastic ORM library for Golang
  • Logger - Structured, pluggable logging for Go.
  • Air - Live reload for Go apps (Docker Development)

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp