Initial commit: FunStat MCP Server Go implementation

- Telegram integration for customer statistics
- MCP server implementation with rate limiting
- Cache system for performance optimization
- Multi-language support
- RESTful API endpoints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
你的用户名
2025-11-04 15:28:06 +08:00
commit 8d1ce4598d
18 changed files with 1940 additions and 0 deletions

70
internal/cache/cache.go vendored Normal file
View File

@@ -0,0 +1,70 @@
package cache
import (
"sync"
"time"
)
type entry struct {
value string
expires time.Time
}
type Cache struct {
ttl time.Duration
mu sync.RWMutex
values map[string]entry
}
func New(ttl time.Duration) *Cache {
if ttl <= 0 {
ttl = time.Hour
}
return &Cache{
ttl: ttl,
values: make(map[string]entry),
}
}
func (c *Cache) Get(key string) (string, bool) {
c.mu.RLock()
e, ok := c.values[key]
c.mu.RUnlock()
if !ok {
return "", false
}
if time.Now().After(e.expires) {
c.mu.Lock()
delete(c.values, key)
c.mu.Unlock()
return "", false
}
return e.value, true
}
func (c *Cache) Set(key string, value string) {
c.mu.Lock()
c.values[key] = entry{
value: value,
expires: time.Now().Add(c.ttl),
}
c.mu.Unlock()
}
func (c *Cache) ClearExpired() int {
now := time.Now()
c.mu.Lock()
removed := 0
for k, v := range c.values {
if now.After(v.expires) {
delete(c.values, k)
removed++
}
}
c.mu.Unlock()
return removed
}
func (c *Cache) TTL() time.Duration {
return c.ttl
}