Documentation ¶
Overview ¶
Package s3 contains gotd storage implementations using S3 protocol.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SessionStorage ¶
type SessionStorage struct {
// contains filtered or unexported fields
}
SessionStorage is a MTProto session S3 storage.
Example ¶
package main import ( "context" "fmt" "os" "os/signal" "github.com/go-faster/errors" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" "github.com/gotd/td/telegram" "github.com/t2bot/gotd-contrib/s3" ) func s3Storage(ctx context.Context) error { accessKeyID := "Q3AM3UQ867SPQQA43P2F" secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" db, err := minio.New("play.min.io", &minio.Options{ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), }) if err != nil { return errors.Errorf("create s3 storage: %w", err) } storage := s3.NewSessionStorage(db, "telegram", "session") client, err := telegram.ClientFromEnvironment(telegram.Options{ SessionStorage: storage, }) if err != nil { return errors.Errorf("create client: %w", err) } return client.Run(ctx, func(ctx context.Context) error { _, err := client.Auth().Bot(ctx, os.Getenv("BOT_TOKEN")) return err }) } func main() { ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() if err := s3Storage(ctx); err != nil { _, _ = fmt.Fprintf(os.Stderr, "%+v\n", err) os.Exit(1) } }
Output:
func NewSessionStorage ¶
func NewSessionStorage(client *minio.Client, bucketName, objectName string) SessionStorage
NewSessionStorage creates new SessionStorage.
func (SessionStorage) LoadSession ¶
func (s SessionStorage) LoadSession(ctx context.Context) ([]byte, error)
LoadSession implements session.Storage.
func (SessionStorage) StoreSession ¶
func (s SessionStorage) StoreSession(ctx context.Context, data []byte) error
StoreSession implements session.Storage.
Click to show internal directories.
Click to hide internal directories.