mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-13 12:17:29 +08:00
fix
This commit is contained in:
@@ -45,6 +45,13 @@ func (c *BaseChannel) IsRunning() bool {
|
|||||||
return c.running.Load()
|
return c.running.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *BaseChannel) HealthCheck(ctx context.Context) error {
|
||||||
|
if !c.IsRunning() {
|
||||||
|
return fmt.Errorf("%s channel not running", c.name)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *BaseChannel) IsAllowed(senderID string) bool {
|
func (c *BaseChannel) IsAllowed(senderID string) bool {
|
||||||
if len(c.allowList) == 0 {
|
if len(c.allowList) == 0 {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ func (m *Manager) GetStatus() map[string]interface{} {
|
|||||||
defer m.mu.RUnlock()
|
defer m.mu.RUnlock()
|
||||||
|
|
||||||
status := make(map[string]interface{})
|
status := make(map[string]interface{})
|
||||||
for name, channel := range m.channels {
|
for name := range m.channels {
|
||||||
status[name] = map[string]interface{}{}
|
status[name] = map[string]interface{}{}
|
||||||
}
|
}
|
||||||
return status
|
return status
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (s *Server) Start() error {
|
|||||||
addr := fmt.Sprintf("%s:%d", s.config.Gateway.Host, s.config.Gateway.Port)
|
addr := fmt.Sprintf("%s:%d", s.config.Gateway.Host, s.config.Gateway.Port)
|
||||||
s.server = &http.Server{
|
s.server = &http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Handler: mux,
|
Handler: s.withCORS(mux),
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.InfoCF("server", "Starting HTTP server", map[string]interface{}{
|
logger.InfoCF("server", "Starting HTTP server", map[string]interface{}{
|
||||||
@@ -67,3 +67,19 @@ func (s *Server) handleRoot(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
fmt.Fprintf(w, "ClawGo Gateway Running\nTime: %s", time.Now().Format(time.RFC3339))
|
fmt.Fprintf(w, "ClawGo Gateway Running\nTime: %s", time.Now().Format(time.RFC3339))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) withCORS(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With")
|
||||||
|
w.Header().Set("Access-Control-Max-Age", "86400")
|
||||||
|
|
||||||
|
if r.Method == http.MethodOptions {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user