app.d 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Collie - An asynchronous event-driven network framework using Dlang development
  3. *
  4. * Copyright (C) 2015-2018 Shanghai Putao Technology Co., Ltd
  5. *
  6. * Developer: Putao's Dlang team
  7. *
  8. * Licensed under the Apache-2.0 License.
  9. *
  10. */
  11. import std.getopt;
  12. import std.stdio;
  13. import hunt.database;
  14. import hunt.io;
  15. import hunt.system.Memory : totalCPUs;
  16. import http.Processor;
  17. import http.Server;
  18. import DemoProcessor;
  19. void main(string[] args) {
  20. ushort port = 8080;
  21. GetoptResult o = getopt(args, "port|p", "Port (default 8080)", &port);
  22. if (o.helpWanted) {
  23. defaultGetoptPrinter("A simple http server powered by Hunt!", o.options);
  24. return;
  25. }
  26. version (POSTGRESQL) {
  27. DatabaseOption options;
  28. debug {
  29. options = new DatabaseOption(
  30. "postgresql://benchmarkdbuser:[email protected]:5432/hello_world?charset=utf-8");
  31. } else {
  32. options = new DatabaseOption(
  33. "postgresql://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?charset=utf-8");
  34. }
  35. options.setMinimumConnection(totalCPUs*3);
  36. options.setMaximumConnection(totalCPUs*3);
  37. dbConnection = new Database(options);
  38. }
  39. AbstractTcpServer httpServer = new HttpServer!(DemoProcessor)("0.0.0.0", port, totalCPUs);
  40. writefln("listening on http://%s", httpServer.bindingAddress.toString());
  41. httpServer.start();
  42. }