forked from godror/godror
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_tznames.go
67 lines (62 loc) · 1.29 KB
/
generate_tznames.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
60
61
62
63
64
65
66
67
//go:build never
// +build never
// Copyright 2021 The Godror Authors
package main
import (
"archive/zip"
"bufio"
"bytes"
"context"
"flag"
"log"
"os"
"os/exec"
"path/filepath"
"sort"
"strings"
"time"
)
func main() {
if err := Main(); err != nil {
log.Fatalf("%+v", err)
}
}
func Main() error {
// flagPackage := flag.String("pkg", "godror", "package name to use")
flagOut := flag.String("o", "", "output file name")
flag.Parse()
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
b, err := exec.CommandContext(ctx, "go", "env", "GOROOT").Output()
if err != nil {
return err
}
fn := filepath.Join(string(bytes.TrimSpace(b)), "lib", "time", "zoneinfo.zip")
log.Printf("go env GOROOT: %s -> fn=%q", b, fn)
zr, err := zip.OpenReader(fn)
if err != nil {
return err
}
defer zr.Close()
names := make([]string, 0, len(zr.File))
for _, f := range zr.File {
if f.Mode().IsDir() {
continue
}
names = append(names, strings.ToLower(f.Name)+f.Name)
}
sort.Strings(names)
fh := os.Stdout
if !(*flagOut == "" || *flagOut == "-") {
if fh, err = os.Create(*flagOut); err != nil {
return err
}
}
defer fh.Close()
bw := bufio.NewWriter(fh)
for _, name := range names {
bw.WriteString(name)
bw.WriteByte('\n')
}
return fh.Close()
}