🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

github.com/sudachi0114/go-mvc

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/sudachi0114/go-mvc

v0.0.0-20210309065728-a638fed7e3e7
Source
Go
Version published
Created
Source

Go で MVC/CRUD な web アプリケーションを作る

お勉強プロジェクトです。Go で (とても簡単な) webアプリケーションを作ります。 MVCフレームワークに則ったものにします。CRUD処理ができるようにします。

勉強したいこと

  • Golang
    • Go で CRUD (DB 連携・処理)
    • Go で開発する時のパッケージング
  • MVC (アプリケーションアーキテクチャ)

作るアプリケーション

  • 『ユーザ』というモデルを持つ
  • ユーザモデルの操作ができるコントローラーを持つ
  • ユーザモデルのコントローラーは『登録 (Create)、表示 (Read)、修正(Update)、削除 (Delete)』ができる
  • (コントローラーと、ルーティンは分離したい)

(余裕があれば API 化とかしたい。 あと、テストとかも勉強したいので組み込みたい。)

インストールしたライブラリ

go get github.com/wcl48/valval      # UserModel のバリデーションのため
go get github.com/jinzhu/gorm       # Go ORM ライブラリ (DB とのやりとり用)
go get 	github.com/mattn/go-sqlite3 # Go で DB とやり取りする時のドライバ

注意: gorm を用いて DB に接続する際、必ずドライバも import する ようにする。

import (
	"github.com/jinzhu/gorm"        // gorm
	_ "github.com/mattn/go-sqlite3" // gorm で使うドライバもインポートしないとエラーになる (この場合、sqlite3 のドライバを import )
)

func main() {
	db, err := gorm.Open("DBMS", "Connection")
	if err != nil {
		...
}

実行

main

go run main.go

DB migration

go run db/migrate.go
  • GoでCRUDでMVCなWEBアプリケーションを書く
  • クラッド (CRUD)とは|「分かりそう」で「分からない」

FAQs

Package last updated on 09 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts