Skip to content

Commit

Permalink
feat: add host parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Mar 5, 2022
1 parent f40de25 commit 9021fe3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 9021fe3

Please sign in to comment.