mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-05 22:43:59 +00:00
9072e9eafb
A fully-generated, strongly-typed Go client for the Telegram Bot API. * 176 methods + 301 types generated from Bot API v10.0 * 1408 auto-generated tests (8 scenarios per method) * Typed unions throughout — no 'any' in the public surface * Pluggable HTTP transport and JSON codec (default goccy/go-json) * Built-in retry middleware honouring Telegram's retry_after * Generic dispatcher with filters and conversation handlers * Self-verifying codegen pipeline (regen → audit → emit → run tests) * 14 example bots covering common patterns
50 lines
1007 B
Go
50 lines
1007 B
Go
// Command genapi reads internal/spec/api.json and emits api/*.gen.go.
|
|
//
|
|
// Usage:
|
|
//
|
|
// genapi -input <file> (default: internal/spec/api.json)
|
|
// genapi -outdir <dir> (default: api)
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
input := flag.String("input", "internal/spec/api.json", "IR JSON path")
|
|
outdir := flag.String("outdir", "api", "output directory")
|
|
flag.Parse()
|
|
|
|
if err := run(*input, *outdir); err != nil {
|
|
fmt.Fprintln(os.Stderr, "genapi:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
// run is filled in by P2.T8/T9/T10.
|
|
func run(input, outdir string) error {
|
|
api, err := loadAPI(input)
|
|
if err != nil {
|
|
return fmt.Errorf("load api: %w", err)
|
|
}
|
|
if err := os.MkdirAll(outdir, 0o750); err != nil {
|
|
return err
|
|
}
|
|
e := newEmitter(api, outdir)
|
|
if err := e.emitTypes(); err != nil {
|
|
return err
|
|
}
|
|
if err := e.emitMethods(); err != nil {
|
|
return err
|
|
}
|
|
if err := e.emitEnums(); err != nil {
|
|
return err
|
|
}
|
|
if err := e.emitTests(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|