blob: bb040705b56cb7b4f9ec2c6ef5eb97e3035aba85 (
plain)
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
|
package main
import (
"archive/zip"
"log"
"path"
"runtime"
"sort"
"sync"
)
var timeLocs []string
var tlOnce sync.Once
func listTimeLocations() ([]string, error) {
zoneinfoZip := path.Join(runtime.GOROOT(), "lib", "time", "zoneinfo.zip")
z, err := zip.OpenReader(zoneinfoZip)
if err != nil {
return nil, err
}
defer z.Close()
locs := []string{}
for _, f := range z.File {
if f.Name[len(f.Name)-1] == '/' {
continue
}
locs = append(locs, f.Name)
}
sort.Strings(locs)
return locs, nil
}
func loadTimeLocs() {
tlOnce.Do(func() {
var err error
if timeLocs, err = listTimeLocations(); err != nil {
log.Fatalf("Could not load time locations: %s", err)
}
})
}
|