base

package module
v0.0.0-...-d1ca7b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2018 License: MIT Imports: 17 Imported by: 0

README

go-todo

Goの net/http とReact(ES2015) を利用したTODOアプリです。TODOアプリのフロント実装は tastejs/todomvc を利用しています。

必要なもの

  • Go 1.9以上
  • MySQLクライアント
  • (optional) Docker
    • MySQLをDockerコンテナで動かせるようにもしています。

いろいろな操作

Makefile をみてください。

# 環境設定をするには以下のようにします。
$ make deps

# テストの実行。ただしサーバサイドのみ。
$ make test

# インテグレーションテストの実行。テスト用のデータベースを利用したテストを実行します。
$ make integration-test

データベースマイグレーション

dbconfig.yml に置かれている設定によって接続するデータベースを指定しています。ここではデータベースマイグレーションの手順について説明します。

データベースマイグレーションでは migrations 以下に置かれているSQLを実行するようにしています。

(ローカル開発環境) 初回のみ

開発環境であれば、マイグレーションをする前にデータベースの作成が必要です。以下のようにするとデータベースを作成することができます。デフォルトではデータベース treasure を作成します。

$ make migrate/init

# インテグレーションテスト用のDBを作成するには以下のようにします
$ make migrate/init DBNAME=test-treasure

パスワードをプロンプトで聞かれます。適宜パスワードを答えてください。後述するDocker環境であればデフォルトパスワードは password です。

マイグレーションの実行

次にマイグレーションを実行します。

# マイグレーションを実際には実行しないが適用されるであろうマイグレーションをプレビューすることができます
$ make migrate/dry

# マイグレーションを実行します
$ make migrate/up

# テストデータベースについて実行する場合にはENVを指定します
$ make migrate/up ENV=test

マイグレーションを実行したあとに現在のデータベースの状態を確認するには以下のようにします。

$ make migrate/status
sql-migrate status
+------------+-------------------------------+
| MIGRATION  |            APPLIED            |
+------------+-------------------------------+
| 1_init.sql | 2016-07-21 05:18:52 +0000 UTC |
+------------+-------------------------------+

マイグレーションには rubenv/sql-migrate を利用しています。詳しくはそちらをみるとよいでしょう。

(optional) Docker環境について

MySQLをDockerで用意するようにしています。開発用に使う際には便利でしょう。もちろんlocalhostないしVM内にMySQLを自分で立てても構いません。

各環境でのDockerのインストールについては https://docs.docker.com/engine/installation/ をみてください。

開発用Docker環境を立ち上げるには以下のようにします。

make docker/start

止めるときは

make docker/stop

です。詳しくは Makefile を見てください。

コンテナに関する設定は docker-compose.yml にまとめています。

Acknowledgement

このアプリは学生エンジニア向けインターンシップ Treasure のために用意されたサンプルアプリケーションです。

Documentation

Overview

Copyright 2017 The Go Authors. All rights reserved.

Use of this source code is governed by a BSD-style license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.

This handler implementation is based on gddo. https://github.com/golang/gddo/tree/master/gddo-server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Serverはベースアプリケーションのserverを示します

TODO: dbxをstructから分離したほうが複数人数開発だと見通しがよいかもしれない

func New

func New() *Server

Newはベースアプリケーションを初期化します

func (*Server) Close

func (s *Server) Close() error

func (*Server) Init

func (s *Server) Init(dbconf, env string)

InitはServerを初期化する

func (*Server) Route

func (s *Server) Route() *mux.Router

Routeはベースアプリケーションのroutingを設定します

func (*Server) Run

func (s *Server) Run(addr string)

Directories

Path Synopsis
originally from github.com/golang/gddo/httputil.(ResponseBuffer)
originally from github.com/golang/gddo/httputil.(ResponseBuffer)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL