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?
    • usecase
    • domain: business logic
      • model: store model object struct
      • service: domain service
      • repository: database handler (especialy CRUD)
    • infrastructure
      • persistence
        • datastore
      • network
        • mail
        • aws
        • flentd
        • api ...etc?
    • registry: DIP
  • config: config
  • vendor: libraries

ライブラリ

  • routing
    • gorilla/mux
  • middleware
    • urfave/negroni

レイヤードアーキテクチャ

そもそもレイヤードアーキテクチャとは

想定している利点

  • business logicに対するテストを重点的にやりたい場合、レイヤーは疎結合にしておく1つの指針になりうるか
  • cakephpのfat controllerになりたくない

application

参考

その他

  • 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