Skip to content

Commit

Permalink
embed services-config.json and dmsghttp-config.json in skywire.go (#1873
Browse files Browse the repository at this point in the history
)
  • Loading branch information
0pcom authored Sep 22, 2024
1 parent aac8091 commit 789cef4
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
2 changes: 2 additions & 0 deletions services-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"test": {
"conf": "http://conf.skywire.dev",
"dmsg_discovery": "http://dmsgd.skywire.dev",
"transport_discovery": "http://tpd.skywire.dev",
"address_resolver": "http://ar.skywire.dev",
Expand Down Expand Up @@ -43,6 +44,7 @@
]
},
"prod": {
"conf": "http://conf.skywire.skycoin.com",
"dmsg_discovery": "http://dmsgd.skywire.skycoin.com",
"transport_discovery": "http://tpd.skywire.skycoin.com",
"address_resolver": "http://ar.skywire.skycoin.com",
Expand Down
94 changes: 93 additions & 1 deletion skywire.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,98 @@
// Package skywire skywire.go
package skywire

import (
_ "embed"
"encoding/json"
"log"

"github.com/skycoin/skywire-utilities/pkg/cipher"
)

/*
workaround to avoid go module errors.
Embedded Deployment Defaults
Change the contents of services-config.json and / or dmsghttp-config.json to embed updated values
*/

// ServicesJSON is the embedded services-config.json file
//
//go:embed services-config.json
var ServicesJSON []byte

// DmsghttpJSON is the embedded dmsghttp-config.json file
//
//go:embed dmsghttp-config.json
var DmsghttpJSON []byte

// EnvServices is the wrapper struct for the outer JSON - i.e. 'prod' or 'test' deployment config
type EnvServices struct {
Test json.RawMessage `json:"test"`
Prod json.RawMessage `json:"prod"`
}

// Services are URLs, IP addresses, and public keys of the skywire services as deployed
type Services struct {
DmsgDiscovery string `json:"dmsg_discovery,omitempty"`
TransportDiscovery string `json:"transport_discovery,omitempty"`
AddressResolver string `json:"address_resolver,omitempty"`
RouteFinder string `json:"route_finder,omitempty"`
RouteSetupNodes []cipher.PubKey `json:"route_setup_nodes,omitempty"`
TransportSetupPKs []cipher.PubKey `json:"transport_setup,omitempty"`
UptimeTracker string `json:"uptime_tracker,omitempty"`
ServiceDiscovery string `json:"service_discovery,omitempty"`
StunServers []string `json:"stun_servers,omitempty"`
DNSServer string `json:"dns_server,omitempty"`
SurveyWhitelist []cipher.PubKey `json:"survey_whitelist,omitempty"`
}

// Conf is the configuration URL for the deployment which may be fetched on `skywire cli config gen`
type Conf struct {
Conf string `json:"conf,omitempty"`
}

// Prod is the production deployment services
var Prod Services

// ProdConf is the service configuration address / URL for the skywire production deployment
var ProdConf Conf

// Test is the test deployment services
var Test Services

// TestConf is the service configuration address / URL for the skywire test deployment
var TestConf Conf

// initialize the embedded files into variables
func init() {
var js interface{}
err := json.Unmarshal([]byte(ServicesJSON), &js)
if err != nil {
log.Panic("services-config.json ", err)
}
err = json.Unmarshal([]byte(DmsghttpJSON), &js)
if err != nil {
log.Panic("dmsghttp-config.json ", err)
}
var envServices EnvServices
err = json.Unmarshal(ServicesJSON, &envServices)
if err != nil {
log.Panic(err)
}
err = json.Unmarshal(envServices.Prod, &Prod)
if err != nil {
log.Panic(err)
}
err = json.Unmarshal(envServices.Prod, &ProdConf)
if err != nil {
log.Panic(err)
}
err = json.Unmarshal(envServices.Test, &Test)
if err != nil {
log.Panic(err)
}
err = json.Unmarshal(envServices.Test, &TestConf)
if err != nil {
log.Panic(err)
}
}

0 comments on commit 789cef4

Please sign in to comment.