1
0

main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "imuslab.com/arozos/ReverseProxy/mod/aroz"
  9. "imuslab.com/arozos/ReverseProxy/mod/database"
  10. )
  11. var (
  12. handler *aroz.ArozHandler
  13. sysdb *database.Database
  14. )
  15. //Kill signal handler. Do something before the system the core terminate.
  16. func SetupCloseHandler() {
  17. c := make(chan os.Signal, 2)
  18. signal.Notify(c, os.Interrupt, syscall.SIGTERM)
  19. go func() {
  20. <-c
  21. log.Println("\r- Shutting down demo module.")
  22. //Do other things like close database or opened files
  23. os.Exit(0)
  24. }()
  25. }
  26. func main() {
  27. //Start the aoModule pipeline (which will parse the flags as well). Pass in the module launch information
  28. handler = aroz.HandleFlagParse(aroz.ServiceInfo{
  29. Name: "ReverseProxy",
  30. Desc: "Basic reverse proxy listener",
  31. Group: "Network",
  32. IconPath: "reverseproxy/img/small_icon.png",
  33. Version: "0.1",
  34. StartDir: "reverseproxy/index.html",
  35. SupportFW: true,
  36. LaunchFWDir: "reverseproxy/index.html",
  37. SupportEmb: false,
  38. InitFWSize: []int{420, 640},
  39. })
  40. //Register the standard web services urls
  41. fs := http.FileServer(http.Dir("./web"))
  42. http.Handle("/", fs)
  43. SetupCloseHandler()
  44. //Create database
  45. db, err := database.NewDatabase("sys.db", false)
  46. if err != nil {
  47. log.Fatal(err)
  48. }
  49. sysdb = db
  50. //Start the reverse proxy server in go routine
  51. go func() {
  52. ReverseProxtInit()
  53. }()
  54. //Any log println will be shown in the core system via STDOUT redirection. But not STDIN.
  55. log.Println("ReverseProxy started. Listening on " + handler.Port)
  56. err = http.ListenAndServe(handler.Port, nil)
  57. if err != nil {
  58. log.Fatal(err)
  59. }
  60. }