app_config.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package application
  2. import "git.ali33.ru/fcg-xvii/rest"
  3. func HTTPHeadersCrossOrigin() func() map[string]string {
  4. return func() map[string]string {
  5. return map[string]string{
  6. "Access-Control-Allow-Origin": "*",
  7. "Access-Control-Allow-Methods": "POST, GET, OPTIONS, PUT, DELETE",
  8. "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
  9. }
  10. }
  11. }
  12. type AppConfig struct {
  13. SSL bool
  14. Addr string
  15. Http bool
  16. Websocket bool
  17. Secret []byte
  18. HttpPrefix string
  19. WebsocketPrefix string
  20. HTTPHeaders func() map[string]string
  21. Commands func(string) (rest.IExecuter, bool)
  22. TLSKeyPath string
  23. TLSCertPath string
  24. Core any
  25. OnSocketConnect func(rest.IStream)
  26. OnSocketDisconnect func(rest.IStream)
  27. }
  28. func (s *AppConfig) GetHttpPrefix() string {
  29. if len(s.HttpPrefix) > 0 {
  30. return s.HttpPrefix
  31. }
  32. return "/api/"
  33. }
  34. func (s *AppConfig) GetWebsocketPrefix() string {
  35. if len(s.WebsocketPrefix) > 0 {
  36. return s.WebsocketPrefix
  37. }
  38. return "/ws/"
  39. }
  40. func (s *AppConfig) GetHTTPHeaders() func() map[string]string {
  41. if s.HTTPHeaders != nil {
  42. return s.HTTPHeaders
  43. }
  44. return func() map[string]string {
  45. return map[string]string{}
  46. }
  47. }