save peers RIVM-31

This commit is contained in:
Mihail Slobodyanuk 2022-12-16 22:58:12 +02:00
parent d68d3db702
commit 0b54277ece
7 changed files with 164 additions and 165 deletions

View file

@ -1,14 +1,11 @@
package main
import (
"bytes"
"log"
"os"
"github.com/RiV-chain/RiV-mesh/src/defaults"
"github.com/hjson/hjson-go"
"github.com/webview/webview"
"golang.org/x/text/encoding/unicode"
"github.com/docopt/docopt-go"
)
@ -46,35 +43,10 @@ func main() {
w.SetSize(690, 920, webview.HintFixed)
if confui.IndexHtml == "" {
confui.IndexHtml = getEndpoint()
}
if confui.IndexHtml == "" {
confui.IndexHtml = "http://localhost:19019"
confui.IndexHtml = defaults.GetHttpEndpoint("http://localhost:19019")
}
log.Printf("Opening: %v", confui.IndexHtml)
w.Navigate(confui.IndexHtml)
w.Run()
}
func getEndpoint() string {
if config, err := os.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil {
if bytes.Equal(config[0:2], []byte{0xFF, 0xFE}) ||
bytes.Equal(config[0:2], []byte{0xFE, 0xFF}) {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder()
config, err = decoder.Bytes(config)
if err != nil {
return ""
}
}
var dat map[string]interface{}
if err := hjson.Unmarshal(config, &dat); err != nil {
return ""
}
if ep, ok := dat["HttpAddress"].(string); ok && (ep != "none" && ep != "") {
return ep
}
}
return ""
}