Documentation
¶
Overview ¶
Example ¶
Example demonstrates basic usage of the tales library
// Use a mock S3 server for the example
mockServer := s3mock.New("example-bucket", "us-east-1")
defer mockServer.Close()
// Create logger
logger, err := New(
"example-bucket",
"us-east-1",
WithPrefix("events"),
WithInterval(5*time.Minute),
WithBuffer(1000),
WithClient(func(cfg s3.Config) (s3.Client, error) {
return s3.NewMockClient(mockServer, cfg)
}),
)
if err != nil {
log.Fatal(err)
}
defer logger.Close()
// Log some game events
logger.Log("Player joined the game", 12345)
logger.Log("Player moved to position (100, 200)", 12345)
logger.Log("Player attacked monster", 12345, 67890) // Player and monster
logger.Log("Monster died", 67890)
logger.Log("Player gained 100 XP", 12345)
// Query events for a specific player
from := time.Now().Add(-1 * time.Hour)
to := time.Now().Add(1 * time.Hour)
fmt.Println("Events for player 12345:")
var count int
for _, text := range logger.Query(from, to, 12345) {
fmt.Printf("- %s\n", text)
count++
}
fmt.Printf("Total events: %d\n", count)
// Query events involving both player and monster
fmt.Println("\nEvents involving both player 12345 and monster 67890:")
count = 0
for _, text := range logger.Query(from, to, 12345, 67890) {
fmt.Printf("- %s\n", text)
count++
}
fmt.Printf("Total intersection events: %d\n", count)
Output: Events for player 12345: - Player joined the game - Player moved to position (100, 200) - Player attacked monster - Player gained 100 XP Total events: 4 Events involving both player 12345 and monster 67890: - Player attacked monster Total intersection events: 1
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶ added in v0.0.2
Manager combines logging and querying capabilities and allows closing the service.
type Option ¶
type Option func(*config)
Option configures the Service. All options are optional and may be provided to New when constructing a logger.
func WithBuffer ¶
WithBuffer sets the maximum number of entries kept in memory.
func WithClient ¶
WithClient allows overriding the S3 client creation function.
func WithInterval ¶
WithInterval sets the interval at which in-memory chunks are flushed.
func WithKey ¶
func WithKey(key *aws.SigningKey) Option
WithKey sets the signing key to use for the S3 client.
func WithPrefix ¶
WithPrefix sets the S3 key prefix to use when storing objects.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides high-performance, memory-efficient logging and querying.
func New ¶
New creates a new logger using the provided S3 bucket and region. Optional behaviour can be configured via Option functions.