Giter Site home page Giter Site logo

golang_rest_example_clone's Introduction

golang-rest-example

my version

Docker version 20.10.12, build e91ed57
docker-compose version 1.29.2, build 5becea4c

setup

install

run DB/DB コンテナを起動

$ docker-compose up -d #DBコンテナ起動
$ docker-compose down #DBコンテナ停止

run app/api server を起動

  1. setup environment/環境変数を設定(内容は.env.sample ファイル参照)
    $ export PORT=<PORT>
    $ export MYSQL_DSN=<MYSQL_DSN>
    $ export ALLOW_CORS_ORIGIN=<ALLOW_CORS_ORIGIN>
  2. command/ローカルで api server を起動
    $ make run #go run ./cmd/api/main.go
  3. check endpoint/ブラウザで動作確認
    $ localhost:<PORT>/version #ex  localhost:8080/version
    $ localhost:<PORT>/healthz #ex localhost:8080/healthz

test with linux/go でテストを実行

$ make test #go test ./...

curl/http request/HTTP リクエスト(動作確認結果のキャプチャあり)

$ curl -X GET localhost:8080/version #バージョン確認(動作確認も兼ねています)
$ curl -X GET localhost:8080/v1/user/{id} -H "Content-Type: application/json" #idを指定して該当のuserを取得
$ curl -X GET localhost:8080/v1/user/all -H "Content-Type: application/json" #userテーブルの一覧(全件)を取得
$ curl -X POST localhost:8080/v1/user -H "Content-Type: application/json" --data-raw '{"name": "user"}' #usersテーブルに指定したnameのuserレコードを追加
$ curl -X DELETE localhost:8080/v1/user/{id} -H "Content-Type: application/json" #idを指定して該当のuserをテーブルから削除

Architecture

DDD/Clean Architecture

pkg

  • command: 各 pkg を初期化
  • config: 設定を管理
  • domain: 目的の明確化
  • handler: ルーティング
  • infrastructure
    • persistence: クエリ
  • io: DB 接続
  • middleware: リクエストの前処理等
  • service: 複数の UseCase を纏める
  • server: API Server の設定
  • version: tool バージョン管理

追加予定の機能

  • テンプレートエンジン 2023/2/6 up
  • csv インポート
  • csv エクスポート
  • ファイルアップロード
  • メール送信
  • gorilla → chi 2023/2/11 up

golang_rest_example_clone's People

Stargazers

 avatar

Watchers

 avatar

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.