package
0.0.0-20240711123734-c091ff3b1106
Repository: https://github.com/hgsgtk/go-snippets.git
Documentation: pkg.go.dev
# README
layerd-basic
レイヤードアーキテクチャになんとなく沿う
パッケージ構成
- src: application code
- presenter
- api
- server
- auth
- handler
- middleware
- router?
- server
- api
- usecase
- domain: business logic
- model: store model object struct
- service: domain service
- repository: database handler (especialy CRUD)
- infrastructure
- persistence
- datastore
- network
- aws
- flentd
- api ...etc?
- persistence
- registry: DIP
- presenter
- config: config
- vendor: libraries
ライブラリ
- routing
- gorilla/mux
- middleware
- urfave/negroni
レイヤードアーキテクチャ
そもそもレイヤードアーキテクチャとは
想定している利点
- business logicに対するテストを重点的にやりたい場合、レイヤーは疎結合にしておく1つの指針になりうるか
- cakephpのfat controllerになりたくない
application
- https://speakerdeck.com/sonatard/next-currency-gaego?slide=29
- domain model, infra(db), 外部APIなどの取りまとめ
- ここにはビジネスロジックは書かない
- domain modelの利用者
参考
- Goのパッケージ構成の失敗遍歴と現状確認 by @timakinさん
- pospomeさんレイヤについて
- recruit lifestyle package構成について
- ドメインモデル貧血症
- go clent architecute sample project
- https://qiita.com/little_hand_s/items/ebb4284afeea0e8cc752
- https://qiita.com/oshiro/items/65d108e533a36c87a6da
- clean architecture sample
- https://golang.org/pkg/context/
- Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it. The Context should be the first parameter, typically named ctx:
- middlewareについて
その他
- mux & negroni
// Run run http server
func Run() error {
r := mux.NewRouter()
r.HandleFunc("/users/", handler.IndexHandler)
n := negroni.Classic()
n.UseHandler(r)
return http.ListenAndServe(":8080", n)
}
- httpauth: basic認証
// Run run http server
func Run() error {
r := mux.NewRouter()
r.HandleFunc("/users/", handler.IndexHandler)
http.Handle("/", httpauth.SimpleBasicAuth("test", "test")(r))
return http.ListenAndServe(":8080", nil)
}
-> % curl -u test:test http://localhost:8080/users/ Hello, http server.
# Packages
No description provided by the author