diff --git a/cmd/getdoc/main.go b/cmd/getdoc/main.go index 1e3ce4c..8aea552 100644 --- a/cmd/getdoc/main.go +++ b/cmd/getdoc/main.go @@ -17,6 +17,7 @@ import ( func main() { dir := flag.String("dir", filepath.Join(os.TempDir(), "getdoc"), "working directory") outDir := flag.String("out-dir", "", "path to write schema") + host := flag.String("host", "core.telegram.org", "host") outFile := flag.String("out-file", "", "filename of schema") readonly := flag.Bool("readonly", false, "read-only mode") pretty := flag.Bool("pretty", false, "pretty json output") @@ -24,6 +25,7 @@ func main() { client, err := dl.NewClient(dl.Options{ Path: filepath.Join(*dir, "cache"), + Host: *host, Readonly: *readonly, }) if err != nil { diff --git a/dl/dl.go b/dl/dl.go index e50035f..3b69d2d 100644 --- a/dl/dl.go +++ b/dl/dl.go @@ -20,11 +20,13 @@ type Client struct { rate ratelimit.Limiter http HTTPClient cache cache.Cacher + host string readonly bool } type Options struct { Client HTTPClient + Host string Path string Readonly bool FromZip bool @@ -38,10 +40,14 @@ func NewClient(opt Options) (*Client, error) { if opt.Client == nil { opt.Client = http.DefaultClient } + if opt.Host == "" { + opt.Host = "core.telegram.org" + } c := &Client{ http: opt.Client, readonly: opt.Readonly, + host: opt.Host, rate: ratelimit.New(10), } @@ -72,7 +78,7 @@ func (c *Client) download(ctx context.Context, layer int, key string) ([]byte, e // `stel_dev_layer=117` u := &url.URL{ Scheme: "https", - Host: "core.telegram.org", + Host: c.host, Path: key, } req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody)