-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
main.go
59 lines (51 loc) · 1.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Binary dlkey extracts public keys from remote repo.
package main
import (
"flag"
"fmt"
"io"
"net/http"
"net/url"
"os"
"path"
"github.com/gotd/td/internal/keyparser"
)
func main() {
var (
name = flag.String("f", "mtproto_dc_options.cpp", "file name to download")
base = flag.String("base", "https://raw.githubusercontent.com/telegramdesktop/tdesktop", "base url")
branch = flag.String("branch", "dev", "branch to use")
dir = flag.String("dir", "Telegram/SourceFiles/mtproto/", "directory")
out = flag.String("o", "", "output file name (blank to stdout)")
)
flag.Parse()
u, err := url.Parse(*base)
if err != nil {
panic(err)
}
u.Path = path.Join(u.Path, *branch, *dir, *name)
res, err := http.Get(u.String())
if err != nil {
panic(err)
}
defer func() { _ = res.Body.Close() }()
if res.StatusCode/100 != 2 {
panic(fmt.Sprintf("status code %d", res.StatusCode))
}
var outWriter io.Writer = os.Stdout
if *out != "" {
w, err := os.Create(*out)
if err != nil {
panic(err)
}
defer func() {
if err := w.Close(); err != nil {
panic(err)
}
}()
outWriter = w
}
if err := keyparser.Extract(res.Body, outWriter); err != nil {
panic(err)
}
}