Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/getdoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ 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")
flag.Parse()

client, err := dl.NewClient(dl.Options{
Path: filepath.Join(*dir, "cache"),
Host: *host,
Readonly: *readonly,
})
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion dl/dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
}

Expand Down Expand Up @@ -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)
Expand Down