index.d 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Hunt - a framework for web and console application based on Collie using Dlang development
  3. *
  4. * Copyright (C) 2015-2016 Shanghai Putao Technology Co., Ltd
  5. *
  6. * Developer: putao's Dlang team
  7. *
  8. * Licensed under the BSD License.
  9. *
  10. */
  11. module app.controller.index;
  12. import hunt.application;
  13. import std.experimental.logger;
  14. import std.exception;
  15. import std.datetime;
  16. import std.conv;
  17. import std.string;
  18. version(USE_ENTITY) import app.model.index;
  19. class IndexController : Controller
  20. {
  21. mixin MakeController;
  22. this()
  23. {
  24. }
  25. Response res(){return request.createResponse();}
  26. @Action void json()
  27. {
  28. import std.json;
  29. JSONValue js = JSONValue([
  30. "message" : "Hello, World!"
  31. ]);
  32. res.setHeader("Date",printDate);
  33. res.json(js);
  34. }
  35. @Action void plaintext()
  36. {
  37. res.setHeader("Date",printDate);
  38. res.plain("Hello, World!");
  39. }
  40. private string printDate() {
  41. DateTime date = cast(DateTime)Clock.currTime;
  42. return format(
  43. "%.3s, %02d %.3s %d %02d:%02d:%02d GMT", // could be UTC too
  44. to!string(date.dayOfWeek).capitalize,
  45. date.day,
  46. to!string(date.month).capitalize,
  47. date.year,
  48. date.hour,
  49. date.minute,
  50. date.second);
  51. }
  52. }