示例#1
0
func main() {
	var err error

	db := db.NewDb()
	defer db.Disconnect()

	dependencyContainer := app.NewDependencyContainer(db)

	request := io.NewRequestFromArgs(os.Args)
	response := io.NewResponse()

	optionsApplier := lib.NewOptionsApplier()
	optionsApplier.Apply(request, response)

	validator := lib.NewValidator()
	err = validator.ValidateRequest(request)
	if err != nil {
		response.AddError(err)
	} else {
		interActorLocator := interactors.BuildInteractorLocator(dependencyContainer)
		dispatcher := lib.NewDispatcher(interActorLocator)
		interactor := dispatcher.Dispatch(request, response)

		err = validator.ValidateRequestByInteractor(request, interactor)
		if err != nil {
			response.AddError(err)
		} else {
			interactor.Execute(request, response)
		}
	}

	if response.HasErrors() {
		log.Fatal(response.Errors)
	}

	if response.Verbosity && len(response.Messages) > 0 {
		fmt.Println()
		for _, msg := range response.Messages {
			fmt.Println(msg)
		}
	}
}
示例#2
0
func main() {
	db := db.NewDb()
	dependencyContainer := app.NewDependencyContainer(db)
	http.ListenAndServe(":8080", dependencyContainer.CreateMuxRouter())
}