Skip to content

Commit 353606f

Browse files
authored
Merge pull request #8 from 117503445/117503445/json-output
output json for debug & view
2 parents 4a054ae + a38938a commit 353606f

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rule-set
2+
*.db

sing-geoip/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"io"
67
"net"
78
"net/http"
@@ -239,6 +240,22 @@ func release(source string, destination string, output string, ruleSetOutput str
239240
return err
240241
}
241242
outputRuleSet.Close()
243+
244+
srsPath, _ = filepath.Abs(filepath.Join(ruleSetOutput, "geoip-"+countryCode+".json"))
245+
os.Stderr.WriteString("write " + srsPath + "\n")
246+
outputRuleSet, err = os.Create(srsPath)
247+
if err != nil {
248+
return err
249+
}
250+
je := json.NewEncoder(outputRuleSet)
251+
je.SetEscapeHTML(false)
252+
je.SetIndent("", " ")
253+
err = je.Encode(plainRuleSet)
254+
if err != nil {
255+
outputRuleSet.Close()
256+
return err
257+
}
258+
outputRuleSet.Close()
242259
}
243260

244261
setActionOutput("tag", *sourceRelease.Name)

sing-geosite/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/sha256"
66
"encoding/hex"
7+
"encoding/json"
78
"io"
89
"net/http"
910
"os"
@@ -238,6 +239,22 @@ func generate(release *github.RepositoryRelease, output string, cnOutput string,
238239
return err
239240
}
240241
outputRuleSet.Close()
242+
243+
srsPath, _ = filepath.Abs(filepath.Join(ruleSetOutput, "geosite-"+code+".json"))
244+
os.Stderr.WriteString("write " + srsPath + "\n")
245+
outputRuleSet, err = os.Create(srsPath)
246+
if err != nil {
247+
return err
248+
}
249+
je := json.NewEncoder(outputRuleSet)
250+
je.SetEscapeHTML(false)
251+
je.SetIndent("", " ")
252+
err = je.Encode(plainRuleSet)
253+
if err != nil {
254+
outputRuleSet.Close()
255+
return err
256+
}
257+
outputRuleSet.Close()
241258
}
242259
return nil
243260
}

0 commit comments

Comments
 (0)