forked from ringsaturn/tzf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 758 Bytes
/
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
// CLI tool to convert GeoJSON based Timezone boundary to tzf's Probuf format.
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
"github.com/Alfex4936/tzf/convert"
"google.golang.org/protobuf/proto"
)
func main() {
jsonFilePath := os.Args[1]
rawFile, err := os.ReadFile(jsonFilePath)
if err != nil {
panic(err)
}
boundaryFile := &convert.BoundaryFile{}
if err := json.Unmarshal(rawFile, boundaryFile); err != nil {
panic(err)
}
output, err := convert.Do(boundaryFile)
if err != nil {
panic(err)
}
outputPath := strings.Replace(jsonFilePath, ".json", ".pb", 1)
outputBin, _ := proto.Marshal(output)
f, err := os.Create(outputPath)
if err != nil {
panic(err)
}
_, _ = f.Write(outputBin)
fmt.Println(outputPath)
}