handler.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package webapi
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "log/slog"
  7. "net/http"
  8. "github.com/mk6i/open-oscar-server/server/webapi/handlers"
  9. "github.com/mk6i/open-oscar-server/state"
  10. )
  11. type Handler struct {
  12. AuthService AuthService
  13. BuddyListRegistry BuddyListRegistry
  14. CookieBaker CookieBaker
  15. ICBMService ICBMService
  16. LocateService LocateService
  17. Logger *slog.Logger
  18. OServiceService OServiceService
  19. SessionRetriever SessionRetriever
  20. BuddyBroadcaster BuddyBroadcaster
  21. OSCARConfig OSCARConfig
  22. BuddyListManager interface{}
  23. RecalcWarning func(ctx context.Context, instance *state.SessionInstance) error
  24. LowerWarnLevel func(ctx context.Context, instance *state.SessionInstance)
  25. ChatSessionManager ChatSessionManager
  26. FeedbagService FeedbagService
  27. DirSearchService DirSearchService
  28. IconSource handlers.BuddyIconSource
  29. }
  30. func (h Handler) GetHelloWorldHandler(w http.ResponseWriter, r *http.Request) {
  31. _, _ = fmt.Fprintf(w, "WebAPI Server Running\n")
  32. // Must return the same JSON envelope as other Web AIM APIs.
  33. h.Logger.Info("webapi root GET", "remote", r.RemoteAddr, "host", r.Host, "path", r.URL.Path)
  34. w.Header().Set("Content-Type", "application/json; charset=utf-8")
  35. resp := map[string]interface{}{
  36. "response": map[string]interface{}{
  37. "statusCode": 200,
  38. "statusText": "OK",
  39. "data": map[string]interface{}{},
  40. },
  41. }
  42. _ = json.NewEncoder(w).Encode(resp)
  43. }